In the code area, I saw a code for generating site snapshots. after reading the code for half a day, I found that the author only posted the business code. Instead, the code for generating snapshot images at the core was not provided. I used to remember that google search provided site thumbnails. at that time, it was amazing, but it didn't take time to do in-depth research. I met again yesterday, so let's investigate it by the way. Installation extension:
(1) The following is the installation process on linux. If git is not installed, run yum install git first.
Install 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 // you can ignore the actual execution in which php is executed/casperjs/bin/casperjs
(2) install phantomjs,: http://phantomjs.org/download.html
After the download, the operation is very simple. you can directly move the decompressed in \ phantomjs to usr \ local \ bin \ phantomjs.
Test phantomjs -- if there is a result of version, no error is reported. The installation is OK.
(3) install fonts
1. first obtain a set of "" Library (Google click), which contains two files: msyh. ttf (common) and msyhbd. ttf (bold );
2. create a sub-directory under the/usr/share/fonts directory, for example, win. the command is as follows:
The code is as follows:
# Mkdir/usr/share/fonts/win
3. copy msyh. ttf and msyhbd. ttf to this directory. for example, if the two files are stored in/root/Desktop, run the following command:
The code is as follows:
# Cd/root/Desktop
# Cp msyh. ttf msyhbd. ttf/usr/share/fonts/win/
4. create a font index to update the font cache:
The code is as follows:
# Cd/usr/share/fonts/win
# Mkfontscale (if mkfontscale: command not found is prompted, you must install it yourself # yum install mkfontscale)
# Mkfontdir
# Fc-cache (if fc-cache: command not found is prompted, install # yum install fontconfig)
Now, 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 this sentence is not added, the error "Fatal: [Errno 2] No such file or directory; did you install phantomjs? ", For more information, see http://mengkang.net/87.html putenv ("PHANTOMJS_EXECUTABLE =/usr/local/bin/phantomjs"); $ command = "phantomjs. js {$ url} {$ filePath} "; @ exec ($ command); exit ($ filePath) ;}?>
Snapshot generation