For one of the projects that I am working on, I needed a website capture utility, that will dump output into a png file. I couldn't find any one-stop-shop for getting it done. There are many websites that have this service (see references towards the end in the post), however I needed something where I have access to the source code, so that I could tweak it to my needs Also something in ruby was prefereable, so that I can integrate it with other stuff I am working on. Google, google and google and finally I hit upon an implementation in ruby called moz-snapshooter.rb, which has got a good screen capture facility that uses 'gtkmozembed' , which is an embeddable Gecko rendering widget that GTK applications can embed. This was pretty much it. All that was needed was the ruby binding for gnome2 libraries etc. They can be found here.
So here is the final deal (on ubuntu Dapper) -
1. Get the ruby-gnome2-all package from here
2. Get the firefox-dev package using apt-get. (Note this is required for building the gtkmozembed.)
3. Get the moz-snapshooter.rb
4. Edit it to your needs
5. Fire ruby moz-snapshooter.rb
Most of the things just work out of the box.
Now comes a little tricky part. All of this requires an X server running. So what if one wants to run it on a headless X server? The answer is Xvfb (which is a virtual frame buffer based X server.) Continuing further.
6. Install Xvfb using apt-get.
7. Finally run the 'ruby moz-snapshooter.rb' inside 'xvfb-run' as follows
xvfb-run -s "-screen 800x600x16" ruby moz-snapshooter.rb
Note to pass -s "-screen 800x600x16" option, since most of the websites work well in that resolution.
1. The libgtk-mozembed-ruby package that comes for 'ubuntu' uses the gtkembed.so library provided by mozilla 1.7.X (which is not compiled with pango renderer. It is better to use firefox-dev library and hence build by hand the ruby-gnome2-all package.)
2. The final output resolution image should be of smaller resolution than the one passed to xvfb-run.
3. This is not 'perfect' yet, but a good starting point.
Here are some samples.
1. Google in 150x100 resolution -
2. paahijen.com in 320x200 resolution -
3. Marathi wikipedia in 640x480 resolution -
1. A pygtk implementation by Andrew McCall
2. moz-snapshooter.rb by Mirko Maischberger
3. Ideum screenshot capture prototype