centos install ImageMagick and php's imagick extension

ImageMagick download address:

http://www.imagemagick.org/script/download.php

Source code download address:

http://www.imagemagick.org/script/install-source.php

Get closer to it: https://www.imagemagick.org/download/

 

wget https://www.imagemagick.org/download/ImageMagick.tar.gz

tar zxf ImageMagick.tar.gz

cd ImageMagick-7.0.4-6/

./configure --prefix=/data/server/ImageMagick

make

make install

 

php extension download address: http://pecl.php.net/package/imagick

wget http://pecl.php.net/get/imagick-3.4.3RC4.tgz

tar zxf imagick-3.4.3RC4.tgz 

cd imagick-3.4.3RC4

# Replace the following sentence with the location of your phpize

/data/server/php/bin/phpize 

./configure --with-php-config=/data/server/php/bin/php-config --with-imagick=/data/server/ImageMagick

make 

make install

 

Imagick usage:

convert Converts image formats and sizes, blurs, crops, removes stains, dithers, nears, draws images on top of images, adds new images, generates thumbnails, and more.

identify Describes the format and characteristics of one or more image files.

composite Generate a picture from a picture or a combination of multiple pictures

I often use identify:

/data/server/ImageMagick/bin/identify test.jpg 

test.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 1.255MB 0.000u 0:00.000

这里能看到图片的格式和长宽,以及大小等信息。

 

利用ImageMagick进行图片修改:

1、转换格式:

/data/server/ImageMagick/bin/convert test.jpg test.png

2、缩放:

/data/server/ImageMagick/bin/convert test.jpg -resize 1000x200 200.jpg

可以看到,原大小为1920x1080的图片,按照1000x200缩放以后,其实是按照更小的系数来缩放,保证高度200,宽度则小于1000,尺寸为:356x200.

当然可以只指定宽度来缩放:

/data/server/ImageMagick/bin/convert test.jpg -resize 1000 1000.jpg  

转换结果是1000x563的图片。

也可以只按照高度来缩放:

/data/server/ImageMagick/bin/convert test.jpg -resize x200 200.jpg  

其它用法比如批量处理、水印等功能请百度。

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326783388&siteId=291194637