PHP实现网页截图的方法:首先下载CutyCapt;然后解压tar包;最后使用代码“public function index(){echo '
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
';echo date('
Y-m-d H:m:s')...}”实现截图即可。</p></blockquote>
<p><img src=
"/static/imghw/default1.png"
data-src=
"https://img.php.cn/upload/article/202008/15/2020081509330277584.jpg"
class
=
"lazy"
alt=
"PHP如何实现网页截图"
></p>
<p>推荐:《<a href=
"https://www.php.cn/course/list/29/type/2.html"
target=
"_blank"
>PHP视频教程</a>》</p>
<link rel=
"stylesheet"
href=
"https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-963e387caa.css"
>
<p id=
"content_views"
class
=
"markdown_views prism-tomorrow-night-eighties"
><!-- flowchart 箭头图标 勿删 --><svg xmlns=
"http://www.w3.org/2000/svg"
style=
"display: none;"
><path stroke-linecap=
"round"
d=
"M5,0 0,2.5 5,5z"
id=
"raphael-marker-block"
style=
"-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"
></path></svg></p>
<blockquote><p><strong>如果需要将一个网址的内容做成视图图片输出,则需要辅助工具<code>CutyCapt</code>来实现这一需求</strong></p></blockquote>
<h2>Windows系统</h2>
<ul>
<li>下载CutyCapt<br>CutyCapt下载地址:http:
//sourceforge.net/projects/cutycapt/files/cutycapt/</li>
<li>解压tar包,看到<code>CutyCapt.exe</code> 不需要再点击安装</li>
<li>代码实现(时间需要20多秒):</li>
</ul><div
class
=
"code"
style=
"position:relative; padding:0px; margin:0px;"
><pre
class
=
'brush:php;toolbar:false;'
>
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>';
}
Salin selepas log masuk
注意
(如果直接命令行执行 $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、缘由链接
CutyCapt是一个截图工具
官方网站 http://cutycapt.sourceforge.net/
我主要的目的是解决用php保存网页为图片,废话不多少开始安装CutyCapt
1 2 3 4 5 6 7 8 9 |
|
解决方法
1 |
|
问题
1)截图时候有乱码
2) 执行速度慢
3)截取百度和小松博客,发现按钮上的文字没有显示,应该也是乱码导致的
PS.中文乱码问题
将windows下的中文字体上传至/usr/share/fonts目录,执行下命令fc-cache即可
测试截图
1 2 3 4 |
|
例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Atas ialah kandungan terperinci PHP如何实现网页截图. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!