Site thumbnail generation using khtml2png

For a friend’s project, i investigated various ways to generate a site thumbnail.

The obvious one is to simply go to the desired website using your favorite browser, take a snapshot using your favorite program. Guaranteed to work :).

    For obvious reasons that never became a real option so my googling revealed various services that do this. Some do it for free but in a limited manner , other are pay services but i was not satisfied with their options (or having to pay). The most famous of them is probably Alexa Site Thumbnails (AST) that is an Amazon web service. I didn’t like it either, especially since according to their terms you can’t store the image , but are only allowed to cache it up to 24 hours. Not good enough for me. (It’s dirt cheap though).

    After a little more searching i found out about the fantastic khtml2png utility. What this does is use khtml libs (from kde3.x) to render a site into a png (and a lot of other image types).

    The catch is that it requires an X server, but on their project page they have instructions to run it on a headless machine using Xvfb (an X server running on a virtual frame buffer).

It’s really easy:

On my machine i did:

Xvfb :1 -screen 0 1600x1200x24&
export DISPLAY="localhost:1.0"
khtml2png2 --width 1280 --height 1024 slashdot.png


And that’s it! I can now turn a headless Pentium III i have running various services (mail etc) to my own private , highly configurable web snapshot service.

Comments !