web2thumb: Create thumbnail of webpage without XServer
- April 25th, 2010
- Posted in HTML . Linux
- By Mr. Nerd
- Write comment
A while ago, I needed a tool that could create a screenshot/thumbnail of a webpage. There are actually quite a few available, some are webservices, others rely on the Internet Explorer, but the vast majority makes use of the WebKit rendering engine, which is conveniently integrated in Qt. Pretty much all the tools I came across have one minor flaw though: They require an XServer, at least a virtual one like Xvfb.
I initially used the webkit2png Python script created by Roland Tapken, which works just fine by using the Qt-Python bindings. But since I always wanted to do a little work in Qt, I started porting this handy little script to C++. In the meantime, I came across wkhtmltopdf, a really great tool for HTML to PDF conversion. They also use WebKit for rendering the content and initially had the same problem with the required XServer as well. But they added a little patch to Qt, allowing them to work without X, which is really great if you run a tool like this on a server (less memory/overhead required).
So I used their patch, added a little more dirty hacks to Qt for allowing JavaScript to work as well and the result is a little programm called web2thumb. If it is compiled against the patched Qt version, you can create thumbnails of websites without running X as long as you don’t enable the use of plugins like Flash or Java.
I am very aware of the fact, that there are other tools which do exactly the same as this tool (or even better), furthermore due to my limited C++ skills, the code quality is probably not that good. I’ll put it out here anyway (licensed under the GPL v3), maybe someone finds it useful as well.
For your convenience, I’ll also include a version which is statically linked against the patch Qt library and boost_program_options, so you don’t have to patch & compile Qt yourself. It is packed with UPX, I’m currently limited to providing an i386 binary though.