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 class="brush:php;toolbar:false">'; 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-chinese yum 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.jpg xvfb-run --server-args="-screen 0, 1920x1080x24" CutyCapt --url=http://www.baidu.com --out=2.jpg xvfb-run --server-args="-screen 0, 1920x1080x24" CutyCapt --url=http://www.163.com --out=3.jpg xvfb-run --server-args="-screen 0, 1920x1080x24" CutyCapt --url=http://www.sina.com.cn --out=4.jpg
例子
<?php /* 网页截图功能,必须安装IE+CutyCapt url:要截图的网页 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如何实现网页截图的详细内容。更多信息请关注PHP中文网其他相关文章!

本文比较了酸和基本数据库模型,详细介绍了它们的特征和适当的用例。酸优先确定数据完整性和一致性,适合财务和电子商务应用程序,而基础则侧重于可用性和

本文讨论了确保PHP文件上传的确保,以防止诸如代码注入之类的漏洞。它专注于文件类型验证,安全存储和错误处理以增强应用程序安全性。

本文讨论了在PHP中实施API速率限制的策略,包括诸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之类的库。它还涵盖监视,动态调整速率限制和手

本文讨论了使用password_hash和pyspasswify在PHP中使用密码的好处。主要论点是,这些功能通过自动盐,强大的哈希算法和SECH来增强密码保护

本文讨论了OWASP在PHP和缓解策略中的十大漏洞。关键问题包括注射,验证损坏和XSS,并提供用于监视和保护PHP应用程序的推荐工具。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

记事本++7.3.1
好用且免费的代码编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SublimeText3汉化版
中文版,非常好用