Simple HTML layout engine to convert HTML to an image

gerdemb picture gerdemb · Dec 4, 2008 · Viewed 22k times · Source

I need a tool to automatically convert simple HTML into an image. I will be controlling the HTML input which will consist of simple text formatting tags and possibly image links--I don't need to be able to render arbitrary HTML. Is there a simple way to do this?

I've looked at the HTML layout engines like Gecko and Webkit, but frankly I'm overwhelmed by the number of options they have--I don't need a complete web browser! Is it possible to use these engines in this way? Can someone steer me in the right direction?

Other possibilities like browsershots, rely on screenshots of real browsers, but I'm going to be running this application on a web server with potentially many users so performance is important and I'm afraid this kind of solution won't scale.

Ideas?

EDIT: Sorry forget to mention that my server is running Linux, so Windows solutions won't help. :)

Answer

gerdemb picture gerdemb · Dec 9, 2008

Answering, my own question I found this useful tool which uses WebKit to render a page and then captures the output as an image or even in PDF format!

http://cutycapt.sourceforge.net/

The idea is similar to khtml2png mentioned by Jay, but I liked this implementation better. Also, for future reference, running an X virtual frame-buffer through Xvfb is not nearly as memory intensive as I had feared.