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
- 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
- Make it so it runs at startup
sudo update-rc.d screencap defaults
sudo chmod 700 /etc/init.d/screencap - Now you can restart, or run:
sudo /etc/init.d/screencap start
- 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
- Create the following file: /etc/monit/conf.d/screencap.monitrc
- Run /etc/init.d/monit restart
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!