Web Screenshots with Xvfb and Khtml2Png2

To get that headless Linux server capturing screenshots of web pages we need:

  • Xvfb e.g. apt-get install xvfb
  • Khtml2png2 (and dependencies)

After installation of the above the steps are below and I wrapped it up into a PHP script which also did some database tasks to keep records of the screenshots.

1.Check if the Xvfb is already running

ps aux | grep Xvfb

If it is running you might get a line similar to:

root     18905     1  0 Apr10 ?        00:00:04 Xvfb :0 -screen 0 800x600x24

If Xvfb is not running it will need initialised (these first two steps could also be wrapped into a shell script run on a schedule)

2. Initialise Xvfb

/usr/bin/Xvfb :0 -screen 0 800x600x24

3. Export the display:

DISPLAY=localhost:0.0

4. Run Khtml2Png2

/usr/local/bin/khtml2png2 –visual TrueColor –width 800 –height 600 –disable-js “http://www.google.com” /var/www/vhosts/website/images/webshots/whatever.png

Incidentally, Facebook do not like this browser and so screenshots of any Facebook pages fail.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>