Web page screenshot example program using PHP in LINUX_PHP tutorial

WBOY
Release: 2016-07-13 17:07:49
Original
987 people have browsed it

In the past, we could only take screenshots of web pages in asp.net. Now I will introduce how to use a plug-in in Linux to take screenshots of web pages in PHP. I hope it will be helpful to everyone.

Server side

To realize the screenshot program, you must use the server-side program: http://code.google.com/p/wkhtmltopdf/

You can convert web pages into pdf or images. There are differences between 32-bit and 64-bit. Find a version that suits your server.

Installation

The installation process is very simple: unzip -> find a suitable path to put it down...

Execute

Command line call 1

 代码如下 复制代码
/servers/app/qtwebkit/wkHtmlToImage bKjia.c0m www.bKjia.c0m.png

The default resolution is relatively high, the picture will be very large, and it will take a certain amount of time to generate the picture.

php

The code is as follows
 代码如下 复制代码

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

Copy code

 代码如下 复制代码

ob_start();
//如果将输出的文件名设置为'-',则直接返回文件数据流
passthru('/servers/app/qtwebkit/wkHtmlToImage --width 800 --height 600 -quality 85 weibo.com -');
$fileName = self::cachePath() . '/' . self::name();
$content = ob_get_clean();

//写入图片文件,备用
//file_put_contents($fileName, $content);

//直接输出为图片
header("Content-type: image/png");
echo $content;
?>

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

Detailed usage

The code is as follows
 代码如下 复制代码

yum install fonts-chinese

Copy code
ob_start();
//If the output file name is set to '-', the file data stream will be returned directly
passthru('/servers/app/qtwebkit/wkHtmlToImage --width 800 --height 600 -quality 85 weibo.com -');
$fileName = self::cachePath() . '/' . self::name();
$content = ob_get_clean();

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

//Directly output as a picture
header("Content-type: image/png");
echo $content;
?>

Chinese garbled problem It mainly depends on whether the server supports the Chinese language. If there are garbled characters in the screenshot, just install a Chinese package.
The code is as follows Copy code
yum install fonts-chinese
http://www.bkjia.com/PHPjc/629896.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629896.htmlTechArticleWe could only take screenshots of web pages in asp.net. Now I will introduce how to use a plug-in in linux to take screenshots. PHP can also take screenshots of web pages. I hope it will be helpful to everyone. The server side is real...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template