Install extensions:
(1) The following is my Linux installation process, if not installed Git, please first yum install git
Installing CASPERJS
The code is as follows:
CD/
git clone git://github.com/n1k0/casperjs.git
CD Casperjs
LN-SF/CASPERJS/BIN/CASPERJS/USR/LOCAL/BIN/CASPERJS//Can ignore the actual execution of PHP is performed/casperjs/bin/casperjs
(2) Install PHANTOMJS, download address: http://phantomjs.org/download.html
After downloading the operation is very simple, directly to the decompression \BIN\PHANTOMJS moved to the \USR\LOCAL\BIN\PHANTOMJS on the right. \
Test PHANTOMJS--version Results without error, indicating installation OK
(3) Install fonts
1. First obtain a set of "Microsoft Ya Black" Font library (Google a lot), including two files Msyh.ttf (normal), Msyhbd.ttf (bold);
2. Create a subdirectory in the/usr/share/fonts directory, such as win, with the following command:
The code is as follows:
# Mkdir/usr/share/fonts/win
3. Copy Msyh.ttf and Msyhbd.ttf to this directory, for example, these two files are placed under/root/desktop, using the command:
The code is as follows:
# Cd/root/desktop
# CP Msyh.ttf msyhbd.ttf/usr/share/fonts/win/
4. Create font index information and update font cache:
The code is as follows:
# Cd/usr/share/fonts/win
# Mkfontscale (if prompted Mkfontscale:command not found, you need to install it yourself # Yum install Mkfontscale)
# Mkfontdir
# Fc-cache (if prompted Fc-cache:command not found, you need to install # Yum installs Fontconfig)
At this point, the font has been installed!
<?php if (isset ($_get[' url '))) { set_time_limit (0); $url = Trim ($_get[' url '); $filePath = MD5 ($url). PNG '; if (Is_file ($filePath)) { exit ($filePath); } If you do not add this sentence will be an error "Fatal: [Errno 2] No such file or directory; Did you install PHANTOMJS? ", details refer to http://mengkang.net/87.html putenv (" phantomjs_executable=/usr/local/bin/ Phantomjs "); $command = "Phantomjs phantomjs.js {$url} {$filePath}"; @exec ($command); Exit ($filePath); } ?>
Snapshot generation
var page = require (' webpage '). Create (); var args = require (' system '). Args; var url = args[1]; var filename = args[2]; Page.open (URL, function () { page.render (filename); Phantom.exit (); });
The above mentioned is the whole content of this article, I hope you can like.