Linux to generate snapshots of PHP Web pages (screenshot) (XVFB and Wkhtmltoimage)

Source: Internet
Author: User
Tags bz2 wkhtmltopdf

In the travel strategy, you need to take the introduction page to generate PDF and JPG images, PDF generated by the "Mpdf HTML generated PDF", and HTML generated JPG again jammed. It is intended to be a pure program generation, but in addition to invoking the remote APIs provided by other Web sites to generate JPG, otherwise the Pure program (GD library and built-in functions, or encapsulated classes) did not find the perfect solution.

Install the extended 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. However, the Wkhtmltoimage 0.11 version was downloaded but the following error occurred.

Pixmap:cannot Create a qpixmap when no GUI being used
Qpixmap:cannot Create a qpixmap when no GUI being used
Qpixmap:cannot Create a qpixmap when no GUI being used
Qpixmap:cannot Create a qpixmap when no GUI being used
Qpixmap:cannot Create a qpixmap when no GUI being used
Qpixmap:cannot Create a qpixmap when no GUI being used final mood Sky install wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2 Low version 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
MV Wkhtmltoimage-amd64/usr/bin/wkhtmltoimage
In this way, the installation is successful, you can test wkhtmltoimage http://www.111cn.net/screenshot.png

2, php execution wkhtmltoimage generate pictures

The code is as follows Copy Code

Set_time_limit (0);
Shell_exec ('/usr/local/bin/wkhtmltoimage http://www.111cn.net//usr/local/wwwroot/111cn.net/5eyi.jpg ');

If you use foreach batch generation, sleep (10) is recommended, pausing for a few seconds after each build.

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.