Using PHP to screenshot or implement a page snapshot we need a tool: Xvfb and Wkhtmltoimagek Oh, this tool is currently only available in Linux systems, the following interested friends can enter the reference.
When making a travel strategy, we need to generate PDF and JPG images from the Strategy page, which is generated by the Mpdf HTML generated PDF, and the HTML generated JPG is jammed. It is intended to be generated in a pure program, but in addition to invoking the remote API provided by other Web sites to generate JPG, the simple program (GD library and built-in functions, or packaged classes) did not find a perfect solution.
Last resort, install the extension wkhtmltoimage build.
The installation steps are as follows:
1, server-side download installation wkhtmltoimage,32 and 64-bit difference, the mood of the sky installed is CentOS 5.8 32-bit. But the Wkhtmltoimage 0.11 version was downloaded but the following error occurred,
Pixmap:cannot Create a qpixmap when no GUI is being used
Qpixmap:cannot Create a qpixmap when no GUI is being used
Qpixmap:cannot Create a qpixmap when no GUI is being used
Qpixmap:cannot Create a qpixmap when no GUI is being used
Qpixmap:cannot Create a qpixmap when no GUI is being used
Qpixmap:cannot Create a Qpixmap when the no GUI is being used the final mood of the sky installation wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2 the lower version can be generated normally.
32 Guests
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2
Tar jxf wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2
CP Wkhtmltoimage-i386/usr/local/bin/wkhtmltoimage
64 guests
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2
MV wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2 Wkhtmltoimage-0.10.0_rc2-static-amd64.tar
TAR-XVF Wkhtmltoimage-0.10.0_rc2-static-amd64.tar
MV Wkhtmltoimage-amd64/usr/bin/wkhtmltoimage
In this way, the installation is successful and can be tested Wkhtmltoimage http://www.bKjia.c0m/screenshot.png
2, PHP execution Wkhtmltoimage generated pictures
The code is as follows |
Copy Code |
Set_time_limit (0); Shell_exec ('/usr/local/bin/wkhtmltoimage http://www.bKjia.c0m//usr/local/wwwroot/bkjia.c0m/5eyi.jpg '); |
If a foreach batch generation is recommended, sleep (10) pauses for a few seconds after each build.
http://www.bkjia.com/PHPjc/632948.html www.bkjia.com true http://www.bkjia.com/PHPjc/632948.html techarticle using PHP to screenshot or implement a page snapshot we need a tool: Xvfb and Wkhtmltoimagek Oh, this tool is currently only available in Linux systems, the following interested friends can enter the reference ...