Heim  >  Artikel  >  php教程  >  LINUX中PHP实现网页截屏实例程序

LINUX中PHP实现网页截屏实例程序

WBOY
WBOYOriginal
2016-05-25 16:40:071276Durchsuche

网页截屏以前我们只能在asp.net中实现,下面我来介绍在linux中利用一个插件让php也可以实现网页截屏吧,希望对大家有帮助.

服务器端:为实现截图的程序必须借助服务器端程序,http://code.google.com/p/wkhtmltopdf/

可将网页转换为pdf或者图片,32和64位有区别,找个适合自己服务器的版本.

安装:安装过程十分简单:解压 -> 找个合适的路径放下…

执行:命令行调用1,代码如下:

/servers/app/qtwebkit/wkHtmlToImage phprm.com www.phprm.com.png  

默认的清晰度比较高,图片会很大,生成图片需要一定的时间.

php代码如下:

exec('/servers/app/qtwebkit/wkHtmlToImage phprm.com www.phprm.com.png');

具体的使用方法,代码如下:

<?php  
	ob_start();  
	//如果将输出的文件名设置为&#39;-&#39;,则直接返回文件数据流  
	passthru(&#39;/servers/app/qtwebkit/wkHtmlToImage --width 800 --height 600 -quality 85 weibo.com -&#39;);  
	$fileName = self::cachePath() . &#39;/&#39; . self::name();  
	$content = ob_get_clean();  
	   
	//写入图片文件,备用  
	//file_put_contents($fileName, $content);  
	   
	//直接输出为图片  
	header("Content-type: image/png");  
	echo $content;  
	 

中文乱码问题:主要看服务器是否支持中文语言,如果截图中出现乱码,直接装个中文包就好了,代码如下:

yum install fonts-chinese

文章网址:

随意转载^^但请附上教程地址。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn