take up the phone(Take webpage screenshot from command line in Ubuntu Linux | Binary Tides)
There are many instances when you want to take the screenshot of a webpage from within a php script or the command line. On ubuntu there are several ways to do it and most of them produce a webkit , gecko or khtml rendered screenshot image.
Some of the methods require X session to open a window and take screenshots. So VNC can be used to run in on servers for example. To Setup a VNC server on Ubuntu read this article.
1. wkhtmltopdf
Url :http://code.google.com/p/wkhtmltopdf/
wkhtmltopdf is a command line utility that converts html to pdf using webkit rendering engine.
Install :sudo apt-get install wkhtmltopdf
Usage :Now the google.pdf file should be there in your home directory.
2. wkhtmltoimage
Url :http://code.google.com/p/wkhtmltopdf/
Docs :http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltoimage_0.10.0_rc2-doc.html
It uses the webkit rendering engine.
Download from : http://code.google.com/p/wkhtmltopdf/downloads/list
Extract the archive.
Usage :print?
It should create google.png in home directory with the screenshot of www.google.com
Other options :Quality – Controls the quality/compression of the generation image. Default is 94
print?
Disable images
print?
Disable javascript
print?
Crop the screenshot
print?
1. Can automatically determine the height of the page to take full page screenshots unlike most other utilities.
Disadvantages :1. Fails many times due to unknown reasons with an error saying “Painter not active ”.
2. Cannot render cufon fonts and flash animations. Sometimes it even fails in jquery animations which take long time to load.
3. cutycapt
Url :http://cutycapt.sourceforge.net/
Install :sudo apt-get install subversion libqt4-webkit libqt4-dev g++ cutycapt
Usage :print?
It should create a google.png file in home directory which would have the screenshot of www.google.com
3. khtml2png
khtml2png uses the konqueror rendering engine to create screenshots of web pages.
Download : http://khtml2png.sourceforge.net/index.php?page=download
Install :1. sudo apt-get install kdelibs4-dev zlib1g-dev g++ cmake
2. Extract the khtml2png archive.
3. ./configure
4. make
5. sudo checkinstall (this will create a deb file and install it , so that it can easily uninstalled later).
Usage :print?
This would create a google.png in home directory with the screenshot of www.google.com.
This method requires a running X session. To run it from VNC use as :
Start vnc server :
print?
Run the program in the vnc server :
print?
print?
4. PyWebShot
Url :http://www.coderholic.com/pywebshot-generate-website-thumbnails-using-python/
https://github.com/coderholic/PyWebShot
Pywebshot uses python bindings embedded mozilla ( http://www.mozilla.org/unix/gtk-embedding.html )
Install :1. sudo apt-get install python-gtkmozembed
2. Download pywebshot from https://github.com/coderholic/PyWebShot
Usage :print?
It should create a www.google.com.png in the directory which has the screenshot of size 1024 x 768.
This method requires a running X session , since it opens a window to load the url and then save its screenshot.
So VNC can be used like this :
start vnc server :
print?
Run pywebshot :
print?
1. Can succesfully render cufon fonts, complex/long loading jquery animations.
Disadvantages1. Cannot automatically determine page height to take full page screenshot.
Workaround: If dimensions are available then the dimensions can be specified as the screensize and using such parameters with a virtual monitor can give full page screenshots.
2. Opens up an annoying browers every time on the desktop.
Workaround: Use xvfb.
5. python-webkit2png
Url :1. http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/
2. https://github.com/AdamN/python-webkit2png/
Install :1. sudo apt-get install python-qt4 libqt4-webkit
2. Download package from github and extract the archive.
Usage :print?
It should create a google.png file in the directory with the screenshot of www.google.com
Use with xvfb :On a webserver since Xorg is not running , xvfb can bed used to take the screenshot.
print?
1. Can succesfully render cufon fonts, complex/long loading jquery animations.
Disadvantages1. Fails at CSS3 fonts.
2. Cannot automatically determine page height to take full page screenshot.
Workaround: If dimensions are available then the dimensions can be specified as the screensize and using such parameters with a virtual monitor can give full page screenshots
3. Opens up an annoying browers every time on the desktop
Workaround: Use xvfb,vnc.
The above tools and techniques can be used on a webserver with a language like PHP.
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!