Linux php web page snapshot (screenshot) (xvfb and wkhtmltoimage)

Source: Internet
Author: User
Tags wkhtmltopdf

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.