konqueror --dump-png google.png http://google.com

Clark C. Evans cce at clarkevans.com
Tue Mar 16 22:50:56 CET 2004


On Tue, Mar 16, 2004 at 08:45:25PM +0100, Simon Hausmann wrote:
| I suggest to subscribe to kfm-devel at kde.org. Stephan Kulow and others have 
| been developing a tool to test regressions in khtml. This tool can also make 
| screenshots of rendered websites, I believe. I'm pretty optimistic that this 
| tool can easily be modified to do exactly what you're looking for and the 
| people on kfm-devel might give hints.

Ok.  Although the script below works with Mozilla as well, the
problem is that you have to "sleep" beacuse there isn't a good
way to know the browser is finished rendering.

...

#!/usr/local/bin/python
""" 
    Use a web browser via X frame buffer to generate an PNG
    and EPS image suitable to docbook.
"""
import os, time, signal
from optparse import OptionParser

def main():
    usage = "usage: %prog [-f file] [-r resolution] " + \
            "[-b browser] [-s sleep] location"
    parser = OptionParser(usage)
    parser.add_option("-f", "--file", action="store", 
                      type="string", dest="file",
                      default="output")
    parser.add_option("-r","--resolution",action="store",
                      type="string", dest="resolution",
                      default="640x480")
    parser.add_option("-b","--browser",action="store",
                      type="string", dest="browser",
                      default="konqueror")
    parser.add_option("-s","--sleep",action="store",
                      type="int", dest="sleep",
                      default=10)
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")
    site = args[0]
    xpid = os.spawnlp(os.P_NOWAIT,"Xvfb","Xvfb", ":1","-ac",
                      "-screen","0", options.resolution + "x8")
    os.environ['DISPLAY'] = '127.0.0.1:1.0'
    kpid = os.spawnlp(os.P_NOWAIT,options.browser,options.browser,
                   "-geometry",options.resolution + "+0+0",
                   site)
    time.sleep(options.sleep)
    os.system("xwpick -window root -format epsi %s.eps" % options.file)
    os.system("xwpick -window root -format gif %s.gif" % options.file)
    os.system("gif2png -d -O %s.gif" % options.file)
    try:
      os.kill(kpid,signal.SIGTERM)
    except: pass
    os.kill(xpid,signal.SIGTERM)

if __name__ == '__main__':
    main()


More information about the konq-e mailing list