def __init__(self, screenshot_root=None, username=None, password=None, queue=None, host=None): # Save attributes self.screenshot_root = screenshot_root self.username = username self.password = password self.queue = queue if queue else "screenshots" self.host = host if host else "localhost" # Set up credentials if applicable if self.username and self.password: self.credentials = PlainCredentials(self.username, self.password) else: self.credentials = None # Initialize a QApplication self.application = init_qtgui() # Set up the renderer self.renderer = WebkitRenderer() self.renderer.width = 1024 self.renderer.height = 768 self.renderer.timeout = 10 self.renderer.format = "png"
img = generate_thumbnail(url, width, height) request.setHeader('Content-Type', 'image/png; charset=UTF-8') request.setHeader('content-disposition', 'inline;filename=out.png') print "[Python] Completed OK thumbnail %s" % url return img def render_POST(self, request): return self.render_GET(request); description = "Thumbnail generator webserver" parser = OptionParser(usage="usage: %prog [options] <URL>", description="Thumbnail generator webserver", add_help_option=True) parser.add_option("-p", "--port", type="int", dest="port",default=8080,help="Server Port to listen on (default: %default)") parser.add_option("-x", "--width", type="int", dest="width",default=640,help="Default thumbnail width (default: %default)") parser.add_option("-y", "--height", type="int", dest="height",default=480,help="Default thumbnail height (default: %default)") #parser.add_option("-a", "--aspect", type="string", dest="height",default=480,help="Default thumbnail height (default: %default)") (start_options,args) = parser.parse_args() app = init_qtgui() resource = WebServerMain() factory = Site(resource) reactor.listenTCP(start_options.port, factory) print "[Python] Server start listening on port %s..." % start_options.port reactor.run()