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 |