Take website screenshots on headless linux display

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

One thought on “Take website screenshots on headless linux display

  1. Razvan Mihaiu

    This is great!Yesterday I configured CutyCap to work with xvfb-run. I found out that such a configuration would randomly stop working! It seems that sometimes the Xvfb daemon is not killed by the script – when that happens all subsequent requests will FAIL.You saved me a lot of time with this tutorial – I never become close friend with bash. If I would have to write the ‘screencap’ script from bottom up and also figure out how to call CutyCap with Xvfb as daemon then I would loose at least 1 day of work! With your tutorial I got everything working in 30 minutes!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s