The problem of creating screenshots of web pages directly on the server arises quite rarely, but, as they say, aptly. It is enough sometimes, because Google gives links to some parser of an existing service. But, gentlemen, this is not our method!
Having rummaged, you can find something like a bunch of
xvfb (virtual framebuffer) with some browser, for example
xvfb + opera , or
khtml2png , which pulls a fig cloud of kde'shnyh lib. But one wants some lightweight standalone script ...
Having decided to devote some time to studying the issue, I thoroughly investigated the available tools.
')
So, the first thing that caught my eye:
webkit2png . The script requires Safari itself, which in turn stands on ... Mac OS. Well, maybe someone will come in handy ...
But, the world is full of enthusiasts, and I found the port of this script for normal Nixes using Qt and Python -
webkit2png.py . For work we need only 2 libraries:
libqt4-webkit python-qt4
.
The script has the following arguments:
-x, --xvfb
Start xvfb. By default, not used.
-g, --geometry
Sets the size of the virtual browser window. By default, 0 is set, which means autodetect.
-o, --output
Writes the resulting screenshot to the specified file.
-f, --format
Image format. By default, png.
--scale
Resize Image.
--aspect-ratio
Sets the proportions. Of possible values: “ignore” (default), “keep”, “expand”.
-t, --timeout
Set the request timeout. By default, not used.
--debug
Allows you to trace the process of creating an image. By default, not used.
Call example:
python webkit2png.py http://habrahabr.ru -o habra.png -g 1024 768
In the process of searching for scripts, there were two more (
mozgrab and
html2jpg ) written in perl and using mozilla. They turned out to be quite old and, in my opinion, uncomfortable. It was decided to quit further searches, since the optimal solution has already been found.