DIY site screenshots
The problem of creating screenshots of web pages directly on the server is quite rare, but, as they say, aptly. Grab it sometimes, so google gives links to some parser of an existing service. But gentlemen, this is not our method!
After digging around, you can find something like a bunch of xvfb (virtual framebuffer) with some browser, for example xvfb + opera , or khtml2png , which pulls a bunch of kde’s libs along with it. But I really want some light standalone script ...
Having decided to devote some time to studying the issue, I thoroughly examined the existing tools.
So, the first thing that caught my eye: webkit2png. For the script to work, you need 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 nicks using Qt and Python - webkit2png.py . For work, we need only 2 libraries:
The script has the following arguments:
Starts xvfb. By default, not used.
Specifies the size of the virtual browser window. By default, parameter 0 is set, which means autodetect.
Writes the resulting screenshot to the specified file.
Image format. By default, png.
Resize image.
Sets the aspect ratio. Of the possible values: “ignore” (default), “keep”, “expand”.
Sets the request timeout. By default, not used.
Allows you to track the process of creating an image. By default, not used.
Call example:
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 had already been found.
After digging around, you can find something like a bunch of xvfb (virtual framebuffer) with some browser, for example xvfb + opera , or khtml2png , which pulls a bunch of kde’s libs along with it. But I really want some light standalone script ...
Having decided to devote some time to studying the issue, I thoroughly examined the existing tools.
So, the first thing that caught my eye: webkit2png. For the script to work, you need 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 nicks 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
Starts xvfb. By default, not used.
-g, --geometry
Specifies the size of the virtual browser window. By default, parameter 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 aspect ratio. Of the possible values: “ignore” (default), “keep”, “expand”.
-t, --timeout
Sets the request timeout. By default, not used.
--debug
Allows you to track 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 had already been found.