Linux PHP Web page generation Snapshot (screenshot) (XVFB and Wkhtmltoimage) _php tutorial

Source: Internet
Author: User
Tags wkhtmltopdf
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 ...

  • 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.