ImageMagick是Linux下常用的一款功能强大的图像软件。其实它并非Linux的专属,它也有Windows安装版。本文只关注Linux版本。
下载源代码:ImageMagick.tar.gz,下载地址:http://www.imagemagick.org/script/install-source.php
安装步骤:
将下载的文件放到/usr/local/src目录下,
解压
test@test:/usr/local/src$ sudo tar -xvf ImageMagick.tar.gz
配置
test@test:/usr/local/src/ImageMagick-6.9.0-2$ sudo ./configure --prefix=/usr/local/ImageMagick-6.9.0-2
编译
test@test:/usr/local/src/ImageMagick-6.9.0-2$ sudo make
安装
test@test:/usr/local/src/ImageMagick-6.9.0-2$ sudo make install
安装完成。
添加系统环境路径:
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ sudo gedit /etc/profile
在打开的文件中,添加一行:
export PATH=$PATH:/usr/local/ImageMagick-6.9.0-2/bin
执行:
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ source /etc/profile
查看路径是否添加成功:
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/cmake-3.1.0/bin:/usr/local/ImageMagick-6.9.0-2/bin
测试一下截图功能是否可用:
test@test:~/Downloads$import -pause 3 test.jpg
到~/Downloads/目录下双击打开test.jpg图片,无法打开,显示错误:
试图通过命令行打开:
display ~/Pictures/test.jpg
报错:import: no decode delegate for this image format `test.jpg' @ error/constitute.c/ReadImage/552.
Reason:
Missing the decoding library. Apparently you need to install it and then recompile ImageMagick to work with Jpg files.
解决方案:
1. Go to: http://www.imagemagick.org/download/delegates/ and download the required/missing delegate library. Here I downloaded "jpegsrc.v9a.tar.gz".
2. Put "jpegsrc.v9a.tar.gz" into directory "/usr/local/src"
3. Go to /usr/local/src, and extract:
test@test:/usr/local/src$sudo tar -xvf jpegsrc.v9a.tar.gz
4. The extracted folder name is "/jpeg-9a", execute the following commands to install:
test@test:/usr/local/src/jpeg-9a$sudo ./configure
test@test:/usr/local/src/jpeg-9a$sudo make install
5. Reinstall ImageMagick. (重复之前的安装步骤和添加/usr/local/ImageMagick-6.9.0-2/bin到系统PATH)
重装之后,再测试:
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ import ~/Downloads/567.jpg
import: error while loading shared libraries: libjpeg.so.9: cannot open shared object file: No such file or directory
或者
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ import -pause 3 ~/test.jpg
import: error while loading shared libraries: libMagickCore-6.Q16.so.2: cannot open shared object file: No such file or directory
错误跟之前不一样。这个错误解决方法如下:
test@test:/usr/local/ImageMagick-6.9.0-2/bin$ cd ../lib/
test@test:/usr/local/ImageMagick-6.9.0-2/lib$ pwd
/usr/local/ImageMagick-6.9.0-2/lib
test@test :/usr/local/ImageMagick-6.9.0-2/lib$ sudo ldconfig /usr/local/ImageMagick-6.9.0-2/lib其实就是添加the shared libraries from the new directory “/usr/local/ImageMagick-6.9.0-2/lib” 到the shared library cache。详细原理:To fix this problem, we need to add the library directory to the list used by ldconfig and run it again to rebuild its cache with the shared library files found in the new directory.http://choorucode.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/
再次执行:
test@test:/usr/local/ImageMagick-6.9.0-2/lib$ import ~/Downloads/test.jpg
不再有错误。打开看看:
test@test:/usr/local/ImageMagick-6.9.0-2/lib$ display ~/Downloads/test.jpg
也可以正常打开了。
进文件夹双击图片,显示也正常打开了:
参考:
http://www.imagemagick.org/script/install-source.php
http://blog.ericlamb.net/2008/11/fix-for-convert-no-decode-delegate-for-this-image-format/¥