CutyCapt是一個剪取工具
官方網站 http://cutycapt.sourceforge.net/
我主要的目的是解決用php儲存網頁為圖片,廢話不多少開始安裝CutyCapt
yum install epel-release
#依賴安裝
yum install Xvfb
yum 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);
?>