A snapshot of a Web page that generates picture formats based on LINNUX+PHANTOMJS _php

Source: Internet
Author: User
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.

  • 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.