We need to use xvfb and wkhtmltoimagek to take screenshots in php or take Web snapshots. This tool can only be used in linux systems currently. If you are interested, refer to it.
When creating a travel strategy, you need to generate PDF and Jpg images on the Strategy page. The PDF file uses MPDF to generate Html PDF, And the HTML file to generate Jpg is closed. In the early stage, we plan to generate a Jpg file using a pure Program (GD library, built-in functions, or encapsulated classes) except by calling the Remote API provided by other websites) no perfect solution.
Install the wkhtmltoimage extension.
The installation procedure is as follows:
1. Download and install wkhtmltoimage on the server. 32 and 64-bit are different. centos 5.8 32-bit is installed in the sky. However, wkhtmltoimage 0.11 is downloaded but the following error occurs,
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 no GUI is being usedthe latest version of wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2 can be generated normally.
32-bit
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-bit
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
Music wkhtmltoimage-amd64/usr/bin/wkhtmltoimage
In this way, the installation is successful, you can test wkhtmltoimage http://www.bKjia. c0m/screenshot.png
2. Run wkhtmltoimage in php to generate an image.
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 you use foreach for batch generation, we recommend that you use sleep (10) to pause for several seconds after each generation.