Home >Backend Development >PHP Tutorial >CutyCapt in php implements web page screenshot saving code_PHP tutorial

CutyCapt in php implements web page screenshot saving code_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:12:03933browse

The function of web page screenshots that you may use most is QQ screenshots, or using asp.net to realize screenshots. In fact, we can also directly use php to take web page screenshots. Now I will introduce to you how to use CutyCapt to realize web page screenshots in PHP. If necessary Friends can refer to it.

CutyCapt download address: http://sourceforge.net/projects/cutycapt/files/cutycapt/

Windows CutyCapt does not require installation, just save it directly to your computer.

Then write your php code as follows

The code is as follows Copy code
 代码如下 复制代码

/*
网页截图功能,必须安装IE+CutyCapt
url:要截图的网页
out:图片保存路径
path:CutyCapt路径
cmd:CutyCapt执行命令
比如:http://你php路径.php?url=http://www.bkjia.com
*/
$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);
?>

/*

Web page screenshot function, you must install IE+CutyCapt

url: want to screenshot Web page
out: image saving path
path: CutyCapt path
cmd: CutyCapt execution command
For example: http://yourphp path.php?url=http://www.bkjia. com
*/

$url=$_GET["url"];
代码如下 复制代码
vi /etc/yum.repos.d/atrpms.repo
[atrpms]
name=CentOS $releasever – $basearch – ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

[atrpms-testing]
name=CentOS $releasever – $basearch – ATrpms testing
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

yum update
yum installqt47
yum installqt47-devel
yum installqt47-webkit
yum installqt47-webkit-devel
$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);
?>

If you are a Linux system, you need to simply configure CutyCapt
 代码如下 复制代码
cd /data0/software
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
mv cutycapt/CutyCapt /usr/local/cutycapt
cd /usr/local/cutycapt
qmake
make
Install the website screenshot software CutyCapt


First, install Qt47 first
Add the download source of qt47

The code is as follows Copy code
vi /etc/yum.repos .d/atrpms.repo
[atrpms]
name=CentOS $releasever – $basearch – ATrpmsbaseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1 
 代码如下 复制代码
 
wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt/usr/local/cutycapt/xvfb-run.sh
chmodu+x /usr/local/CutyCapt/xvfb-run.sh
[atrpms-testing]name=CentOS $ releasever – $basearch – ATrpms testingbaseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testinggpgkey=http://ATrpms.net/RPM-GPG-KEY .atrpmsgpgcheck=1enabled=1 yum updateyum installqt47yum installqt47-develyum installqt47-webkityum installqt47-webkit-devel
Maybe there will be an error message herewarning: qt44-x11-4.4.3-10_4.el5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID 66534c2berror: Failed dependencies: libGLU.so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64 libmng .so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64Solution: yum -y installqt-devel* II , install CutyCapt
The code is as follows Copy code
cd /data0/softwaresvn co https://cutycapt.svn.sourceforge.net/svnroot/cutycaptmv cutycapt/CutyCapt /usr/local/cutycaptcd /usr/local/cutycaptqmakemake
An error may be reported heremake: *** [CutyCapt] Error 1Solution: yum update sqliteExecute make again If it still fails qmake-qt47 Execute make again Three, download x-server
The code is as follows Copy code
wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txtmv ./xvfb-run .sh.txt/usr/local/cutycapt/xvfb-run.shchmodu+x /usr/local/CutyCapt/xvfb-run.sh



Four. Install the Chinese package
yum installfonts-chinese


Five. Install ImageMagick
yum installImageMagick

Six. Test:

Seven, download the 64-bit flash plug-in :
The code is as follows
 代码如下 复制代码
/usr/local/cutycapt/xvfb-run.sh --server-args="-screen 0, 1024x768x24"/usr/local/cutycapt/CutyCapt --url=http://www.bkjia.com--out=/tmp/163.jpg
Copy code


/usr/local/cutycapt/xvfb-run.sh --server-args="-screen 0, 1024x768x24"/usr/local/cutycapt/CutyCapt --url=http://www.bkjia .com--out=/tmp/163.jpg

 代码如下 复制代码
cd /data0/software
#wget http://119.188.72.26/1/ishare.down.sina.com.cn/14036482.so?ssig=YB70Xk7Ph9&Expires=1340899200&KID=sina,ishare&ip=1340777795,114.255.44.&fn=libflashplayer.so
http://ishare.iask.sina.com.cn/f/13659493.html
ll /usr/lib64/mozilla/plugins/
lrwxrwxrwx 1 root root 41 06-27 14:00 libflashplayer.so ->/usr/lib64/flash-plugin/libflashplayer.so
cp /data0/software/libflashplayer.so /usr/lib64/flash-plugin/


163.jpg flash is not loaded

The code is as follows
Copy code
cd /data0/software

#wget http://119.188.72.26/1/ishare.down.sina.com.cn/14036482.so?ssig=YB70Xk7Ph9&Expires=1340899200&KID=sina,ishare&ip=1340777795 ,114.255.44.&fn=libflashplayer.so

http:// isare.iask.sina.com.cn/f/13659493.htmllrwxrwxrwx 1 root root 41 06-27 14:00 libflashplayer.so - >/usr/lib64/flash-plugin/libflashplayer.socp /data0/software/libflashplayer.so /usr/lib64/flash-plugin/ Test loaded successfully
http://www.bkjia.com/PHPjc/444600.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444600.htmlTechArticleYou may use QQ screenshots the most, or use asp.net to realize screenshots. In fact, We can also directly use php to take screenshots of web pages. Let me introduce to you...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn