_php instance of a Web page snapshot based on LINNUX+PHANTOMJS implementation to generate picture format

Source: Internet
Author: User

Install extension:
(1) The following is my installation process on Linux, if Git is not installed please yum install git first
Install Casperjs

Copy Code code as follows:

CD/
git clone git://github.com/n1k0/casperjs.git
CD Casperjs
LN-SF/CASPERJS/BIN/CASPERJS/USR/LOCAL/BIN/CASPERJS//Can ignore actual execution of PHP is executed/casperjs/bin/casperjs


(2) Install PHANTOMJS, download address: http://phantomjs.org/download.html
After downloading the operation is very simple, directly unzip the good \BIN\PHANTOMJS moved to \USR\LOCAL\BIN\PHANTOMJS on it. \
The test Phantomjs--version has the result not to complain, the description installs OK

(3) Install fonts
1. First get a set of "Microsoft Ya-Black" Font library (Google a lot), including two files Msyh.ttf (ordinary), Msyhbd.ttf (bold);
2. Create a subdirectory under the/usr/share/fonts directory, such as win, which commands the following:

Copy Code code as follows:

# Mkdir/usr/share/fonts/win

3. Copy Msyh.ttf and Msyhbd.ttf to the directory, for example, the two files are placed under/root/desktop, using the command:

Copy Code code as follows:

# Cd/root/desktop
# CP Msyh.ttf msyhbd.ttf/usr/share/fonts/win/

4. Create font index information, update font caching:

Copy Code code as follows:

# Cd/usr/share/fonts/win
# Mkfontscale (if you are prompted to Mkfontscale:command not found, install it yourself # Yum install Mkfontscale)
# Mkfontdir
# Fc-cache (if prompted Fc-cache:command not found, you will need to install # Yum install 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 the error "Fatal: [Errno 2] No such file or directory; Did you install PHANTOMJS? ", details reference http://mengkang.net/87.html putenv (" Phantomjs_executable=/usr/local/bin/phantomjs "
    ); 
    $command = "Phantomjs phantomjs.js {$url} {$filePath}"; 
  
    @exec ($command); 
  Exit ($filePath); }?> <! DOCTYPE html>  
 
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 entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.