您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP如何实现网页截图

2024/2/28 22:49:50发布28次查看
php实现网页截图的方法:首先下载cutycapt;然后解压tar包;最后使用代码“public function index(){echo 'e03b848252eb9375d56be284e690e873';echo date('y-m-d h:m:s')...}”实现截图即可。
推荐:《php视频教程》
如果需要将一个网址的内容做成视图图片输出,则需要辅助工具cutycapt来实现这一需求
windows系统下载cutycapt
cutycapt下载地址:http://sourceforge.net/projects/cutycapt/files/cutycapt/解压tar包,看到cutycapt.exe  不需要再点击安装代码实现(时间需要20多秒): public function index() { echo '<pre>'; echo date('y-m-d h:m:s').'<br>'; $_get['url'] = 'https://www.aliyun.com/jiaocheng/970387.html'; $url=$_get["url"]; $imgname = rand(10000,99999); $out = 'd:/game/'.$imgname.'.png'; //输出图片地址 $path = 'd:/game/cutycapt.exe'; //工具存储地址 $cmd = "$path --url=$url --out=$out"; echo $cmd.'<br>'; system($cmd, $em); if(!empty($em)){ echo '成功了呢'; }; echo date('y-m-d h:m:s').'<br>'; }
注意(如果直接命令行执行 $cmd报错):qiodevice::read: maxsize argument exceeds qbytearray size limit terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc this application has requested the runtime to terminate it in an unusual way. please contact the application's support team for more information.
处理:
1、开始–运行–输入cmd
2、输入 cd %windir%\system32 (进入windows安装目录的system32文件夹)
3、输入 regsvr32 msxml3.dll
4、缘由链接
linux系统cutycapt是一个截图工具
官方网站 http://cutycapt.sourceforge.net/
我主要的目的是解决用php保存网页为图片,废话不多少开始安装cutycapt
yum install epel-release#依赖安装yum install xvfbyum install xorg-x11-fonts*yum install qtwebkit-devel qt-devel#中文字体yum install fonts-chineseyum install cutycapt#测试使用xvfb-run --server-args="-screen 0, 1920x1080x24" cutycapt --url=http://www.phpsong.com --out=phpsong.jpg如果提示错误libegl warning: dri2: failed to open swrast (search paths /usr/lib64/dri)
解决方法
yum install mesa-dri-drivers
问题
1)截图时候有乱码
2) 执行速度慢
3)截取百度和小松博客,发现按钮上的文字没有显示,应该也是乱码导致的
ps.中文乱码问题
将windows下的中文字体上传至/usr/share/fonts目录,执行下命令fc-cache即可
测试截图
xvfb-run --server-args="-screen 0, 1920x1080x24" cutycapt --url=http://www.phpsong.com --out=1.jpgxvfb-run --server-args="-screen 0, 1920x1080x24" cutycapt --url=http://www.baidu.com --out=2.jpgxvfb-run --server-args="-screen 0, 1920x1080x24" cutycapt --url=http://www.163.com --out=3.jpgxvfb-run --server-args="-screen 0, 1920x1080x24" cutycapt --url=http://www.sina.com.cn --out=4.jpg
例子
<?php/* 网页截图功能,必须安装ie+cutycapturl:要截图的网页out:图片保存路径path:cutycapt路径cmd:cutycapt执行命令比如:http://你php路径.php?url=http://www.111cn.net*/$url=$_get["url"];$imgname=str_replace('http://','',$url);$imgname=str_replace('https://','',$imgname);$imgname=str_replace('.','-',$imgname);$out = 'd:/webroot/test/'.$imgname.'.png';$path = 'd:/webserver/cutycapt.exe';$cmd = "$path --url=$url --out=$out";echo $cmd;system($cmd);?>
以上就是php如何实现网页截图的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product