ImageMagick

What is it?

ImageMagick is an free open source simple software suite for any kind of image manipulation that is used for creating, editing, converting, displaying image files. It can able to read and write over 200 image files such as JPEG, GIF, PNG, TIFF and Photo CD image formats and it is also used for thumbnail or captcha generation. It also includes command line options for creating transparent or animated gif image formats and many more feature like resize, sharpen, rotate or add special effects to an image.

ImageMagick是一个免费的开源简单软件套件,适用于任何类型的图像处理,用于创建,编辑,转换,显示图像文件。它可以读取和写入超过200个图像文件,如JPEG,GIF,PNG,TIFF和Photo CD图像格式,它还可用于缩略图或验证码生成。它还包括用于创建透明或动画gif图像格式的命令行选项以及更多功能,如调整大小,锐化,旋转或向图像添加特殊效果。

安装

1
2
yum install ImageMagick ImageMagick-devel ImageMagick-perl

Yum或者Rpm安装是最简单的,但有时候会出问题,建议从源码安装

1
2
3
4
5
6
wget https://www.imagemagick.org/download/ImageMagick.tar.gz
tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.0.8-5
./configure --prefix=/usr/local/imagemagick
make
make install

使用

Php如果要使用,需要安装imagick扩展。我们使用pecl安装,自动下载,自动编译。

First, install following prerequisite php-pear and gcc packages to compile imagick PHP extension.

1
yum install php-pear gcc

Next, compile the imagick for PHP extension. To do, simple run the following pecl command. It will install ImageMagick and imagick PHP extension module imagick.so under /usr/lib/php/modules directory. If you are using 64-bit system, the module directory path would be /usr/lib64/php/modules.

1
pecl install imagick 

Note: It will ask you to provide Imagemagick installation prefix, simply hit /usr/local/imagemagick.

Now, add the imagick.so extension to /etc/php.ini file.

1
echo extension=imagick.so >> /etc/php.ini

Next, restart Apache web server.

1
service httpd restart

Verify imagick PHP extension by running the following command. You will see imagick extension similar to below.

1
php -m | grep imagick

ghostscript

ImageMagick无法直接实现pdf文档到图片的转换,需要借助于ghostscript软件包

1
2
3
4
5
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs923/ghostpcl-9.23-linux-x86_64.tgz
tar xvzf ghostpcl-9.23-linux-x86_64.tgz
cd ghostpcl-9.23-linux-x86_64
./configure
make && make install

建议Ghostscript使用yum安装,因为安装的时候有一些字体库依赖包

1
yum -y install ghostscrip