In LINUX, PHP implements the web page screenshot instance Program

Source: Internet
Author: User

Web page screenshots were previously implemented only in asp.net. Next I will introduce how to use a plug-in linux to allow php to implement web page screenshots. I hope it will be helpful to you.

Server

The program to be implemented must rely on a server-side program: http://code.google.com/p/wkhtmltopdf/

You can convert a webpage to a pdf or image. There is a difference between 32-bit and 64-bit. Find a version suitable for your server.

Install

The installation process is very simple: extract the package and find a proper path to put it down...

Run

Command Line call 1

The Code is as follows: Copy code
/Servers/app/qtwebkit/wkHtmlToImage bKjia. c0m www.bKjia.c0m.png

The default definition is relatively high, and the image size will be large. It takes some time to generate the image.

Php

The Code is as follows: Copy code

Exec ('/servers/app/qtwebkit/wkHtmlToImage bKjia. c0m www.bKjia.c0m.png ');

Usage

The Code is as follows: Copy code

<? Php
Ob_start ();
// If the output file name is set to '-', the file data stream is directly returned.
Passthru ('/servers/app/qtwebkit/wkHtmlToImage -- width 800 -- height 600-quality 85 weibo.com -');
$ FileName = self: cachePath (). '/'. self: name ();
$ Content = ob_get_clean ();

// Write the image file for backup
// File_put_contents ($ fileName, $ content );

// Directly output as an image
Header ("Content-type: image/png ");
Echo $ content;
?>

Chinese garbled characters

It mainly depends on whether the server supports the Chinese language. If garbled characters appear, simply install a Chinese package.

The Code is as follows: Copy code

Yum install fonts-chinese

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.