How to install imagick in php in Linux

Source: Internet
Author: User
Tags fpm imagemagick phpinfo

Note:
Php installation directory:/usr/local/php5
Php. ini configuration file path:/usr/local/php5/etc/php. ini
Nginx installation directory:/usr/local/nginx
Nginx website root directory:/usr/local/nginx/html
1. Install the compilation tool


Yum install wget make gcc-c ++ gtk +-devel zlib-devel openssl-devel pcre-devel kernel keyutils patch perl
2. Install ImageMagick
System O & M www.111cn.net reminder: qihang01 original content is copyrighted. For reprinting, please indicate the source and original link.
Cd/usr/local/src # enter the package storage directory
Wget http://www.imagemagick.org/download/ImageMagick.tar.gz # Download ImageMagick
Tar zxvf ImageMagick.tar.gz # decompress
Cd ImageMagick-6.7.9-3 # enter the installation directory
./Configure -- prefix =/usr/local/imagemagick # configuration
Make # compile
Make install # install
Export PKG_CONFIG_PATH =/usr/local/imagemagick/lib/pkgconfig/# set environment variables
3. Install imagick
Cd/usr/local/src
Wget http://pecl.php.net/get/imagick-3.0.1.tgz # Download imagick
Tar zxvf imagick-3.0.1.tgz
Cd imagick-3.0.1
/Usr/local/php5/bin/phpize # use phpize to generate the configure configuration file
./Configure -- with-php-config =/usr/local/php5/bin/php-config -- with-imagick =/usr/local/imagemagick # configuration
Make # compile
Make install # install
Note: an error occurs during installation. This error is generally caused by the lack of a compilation toolkit. Follow the prompts to install the corresponding toolkit by referring to the first step.
After the installation is complete, the following interface appears. Remember the following path, which will be used later.
Installing shared extensions:/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/# imagick module path
4. Configure php to support imagick
Vi/usr/local/php5/etc/php. ini # Edit the configuration file and add the following content in the last line:
Extension = "imagick. so"
5. Test
Vi/usr/local/nginx/html/phpinfo. php # Edit and enter the following code:
<? Php
Phpinfo ();
?>
Wq! # Save and exit
Vi/usr/local/nginx/html/imagick. php # Edit and enter the following code:
<? Php
Header ('content-type: image/jpeg ');
$ Image = new Imagick ('www .111cn.net. jpg ');
// If 0 is provided as a width or height parameter,
// Aspect ratio is maintained
$ Image-> thumbnailImage (300,225 );
Echo $ image;
?>

Upload an image www.111cn.net. jpg (the size is 640*480) under the root directory/usr/local/nginx/html/of the website, as shown in the following figure.
Service php-fpm restart # restart php-fpm
Service nginx restart # restart nginx
Open phpinfo. php in the browser, as shown in the following figure. The imagick information is displayed.

Open imagick. php in the browser, as shown in the following figure. The original image is reduced to 300*225.
In the terminal command line, enter:
/Usr/local/imagemagick/bin/convert www.111cn.net. jpg-resize 50% www.111cn.net. png # generate a new image with the original image size of 50%
The original image www.111cn.net. jpg is 640*480, and the generated image www.111cn.net. png is 320*240, which is half the size of the original image! As shown in the following figure:
Now, the installation of imagick in php in Linux is complete!

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.