Here are the steps to setup a linux headless display server to take screenshots of websites using http://cutycapt.sourceforge.net/ and Xvfb. This example is using ubuntu 10.10 64bit.

*this assumes you have cutycapt installed and working – as well as Xvfb

  1. If your taking multiple screenshots (like as a service for example) you’ll want to run Xvfb as a service.  Create the following file in /etc/init.d/screencap

    https://gist.github.com/953399

  2. Make it so it runs at startup

    sudo update-rc.d screencap defaults
    sudo chmod 700 /etc/init.d/screencap
  3. Now you can restart, or run:

    sudo /etc/init.d/screencap start
     

  4. Now from another terminal take the screenshot:

    DISPLAY=:1 /usr/bin/CutyCapt –url=”http://rynop.com” –out=”rynop.jpg” –out-format=jpeg –plugins=off –delay=4000

 

So why not use xvfb-run? I intend to take multiple screenshots, so starting Xvfb before every screenshot, then killing (which xvfb-run does) it alot of wasted overhead.  I see the Xvfb process only takes up ~ 7megs of memory – so its not really all that bloated.

Taking screenshots is pretty slow, as you have to wait for page to render.  If anyone has tips on how to improve performance please let me know.

Extra credit – monitor the service with monit

  1. Create the following file: /etc/monit/conf.d/screencap.monitrc

    https://gist.github.com/953421

  2. Run /etc/init.d/monit restart

 

 

Advertisements