ImageMagick, Imagick, and Ghostscript?

Source: Internet
Author: User
Tags imagemagick

I. Overview of functions

ImageMagick is a third-party image processing software, the function is more powerful than GD. It is recommended that both are installed and do not conflict.

Imagick is an extension module in PHP that invokes the API provided by ImageMagick to perform the operation of the picture.

Ghostscript is a set of free software that is compiled based on the page description language of Adobe, PostScript, and Portable Document Format (PDF).
Ghostscript was originally sold in the PC market in the form of commercial software and was called "Goscript". But because the speed is too slow (half an hour edition A4), the sales are very poor. Later, the conscientious buyer bought the copyright, and changed in the development of Linux, became today's Ghostscript.
Migrated from Linux to other operating systems, such as other Unix, Mac OS X, VMS, Windows, OS/2, and Mac OS Classic.

ImageMagick cannot directly convert a PDF document to a picture, you need to use the Gostscript Package


Second, the installation method

1. Compile and install ImageMagick

# Tar XF imagemagick-6.8.9-9.tar.gz# cd imagemagick-6.8.9-9#./configure--prefix=/usr/local/imagemagick# make# make After installing the installation, remember to configure the./convert Environment variables

2. Compile and install Imagick

# tar-xf imagick-3.2.0rc1.tgz# cd imagick-3.2.0rc1#/usr/local/php/bin/phpize#./configure--with-php-config=/usr/ Local/php/bin/php-config--with-imagick=/usr/local/imagemagick# make && make install

3. Compile and install Ghostscript

# Tar XF ghostscript-9.02.tar.gz# cd ghostscript-9.02#./configure# make# Make install recommendation Ghostscript use Yum installation, Because there are some font libraries that are dependent on package # Yum-y Install Ghostscrip

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/88/wKiom1Szf43gMwX-AAKc4djuQ9o095.jpg "title=" 10.png "Width=" "height=" 163 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:800px;height:163px; "alt=" Wkiom1szf43gmwx-aakc4djuq9o095.jpg "/>


Iii. PHP Load Imagick module

1. PHP Load Imagick dynamic module

# echo ' extension= ' imagick.so ' >>/usr/locla/php/etc/php.ini# service php-fpm restart

2. View Phpinfo page

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/85/wKioL1SzfdSwfEl1AARbxAl58EU117.jpg "title=" 3.png " alt= "Wkiol1szfdswfel1aarbxal58eu117.jpg"/>


Iv. use of the ImageMagick command line

Note: Only install ImageMagick to install Ghostscript effect

Manually use commands to convert pictures to pictures, images to PDFs, etc., but not to convert PDFs to images, the command is as follows:

[Email protected] opt]# lsdocument.pdf imagice.png[[email protected] opt]#/usr/local/imagemagick/bin/convert Imagice.png Nihao_tupian.jpg[[email protected] opt]# lsdocument.pdf imagice.png nihao_tupian.jpg[[email protected] opt ]#/usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdfconvert:no images defined ' nihao_wendang.pdf ' @ error/convert.c/convertimagecommand/3210. [Email protected] opt]# lsdocument.pdf imagice.png nihao_tupian.jpg

Effects after installation of Ghostscript

[Email protected] opt]#/usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdfconvert:no images defined ' Nihao_wendang.pdf ' @ error/convert.c/convertimagecommand/3210[[email protected] opt]# yum-y install ghostscript[[ Email protected] opt]#/usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdf[[email protected] opt]# Lsdocument.pdf imagice.png nihao_tupian.jpg nihao_wendang.pdf


V. Invocation of PHP Program

1, PHP program call Imagick Program

<?php         $pdfFile =$_get[' pdf '];         if (Empty ($pdfFile)) {             $path = '/www/111111.pdf ';                 var_dump (Is_readable ($path));              $pdfFile = ' 111111.pdf ';        }else{              $path = '/www/yanjiuyuan/pdf/'. $pdfFile;         }        if (!file_exists ($path)) {                 echo  "No";         }         $Return =array ();          $filelen =strlen ($pdfFile);         $strFileName = substr ($pdfFile, 0, $filelen-4);         $fp  =  @fopen   (   "./pdf/". $strFileName. ". TXT ",  ' r '  );        if  ($FP)  {             $arr  = unserialize  ( fgets  (  $FP  )  );            $Return = $arr;            fclose  (  $fp  );         }else{             $IM  = new imagick ();             $IM- >setresolution (150,150);             $IM setcomPressionquality (;            ) $IM->readimage ($path);            foreach  ($IM  as   $Key  =>  $Var)  {                  $Var->setimageformat (' png ');                  $Filename  =  '/www/yanjiuyuan/pdf/'  . time ( )  . uniqid ()  .  '. png ';                 if  ($Var->writeimage ($Filename)  == true)  {                    //  $Return [] =  $Filename;                  &nBsp;  array_push ($Return, $Filename);                 }            }              $fp  = fopen  ("/www/ yanjiuyuan/pdf/". $strFileName.". TXT ",  ' W '  );            fwrite  (   $FP, serialize  (  $Return  )  ;             fclose  (  $fp  );        }          $imageHtml =array ();         foreach ($Return  as  $key + $value) {              $strNumber =strlen ($value);            &nbSP; $imPath =substr ($value, $strNumber -27, $strNumber);              $url = ' www/yanjiuyuan/pdf/'. $imPath;              $imageHtml []= $url;        }        print_r ($imageHtml);    ?>

2. Page Access URL

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/88/wKiom1SzgPaxXCfTAAIxFXFMaYM316.jpg "title=" 5.png " alt= "Wkiom1szgpaxxcftaaixfxfmaym316.jpg"/>

3. View the generated pictures

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/88/wKiom1SzgU7wPUEQAAGX2J0AwWk316.jpg "title=" 6.png " alt= "Wkiom1szgu7wpueqaagx2j0awwk316.jpg"/>

This article is from the "Zheng" blog, make sure to keep this source http://467754239.blog.51cto.com/4878013/1602518

ImageMagick, Imagick, and Ghostscript?

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.