1. 在安装ImageMagick之前,请检查下面包已经安装
tiff-3.9.5.tar.gz (rpm -qa|grep libtiff检查是否已经安装)
libpng-1.2.46.tar.gz (rpm -qa|grep libpng检查是否已经安装)
jpegsrc.v6b.tar.gz (rpm -qa|grep libjpeg检查是否已经安装)
freetype-2.3.9.tar.bz2 (rpm -qa|grep freetype检查是否已经安装)
安装方法:
[plain] view plain copy print ?
- tar –zxvf xxx.tar.gz ./configure make make install
tar –zxvf xxx.tar.gz ./configure make make install
注意:jpegsrc.v6b.tar.gz 安装完后用rpm -qa|grep libjpeg 检查,如下结果则正确:
经常碰到红色箭头所指的包没有,则需要单独安装包libjpeg-devel-6b-37.x86_64.rpm,shell命令如下
[plain] view plain copy print ?
- rpm –ivh libjpeg-devel-6b-37.x86_64.rpm
rpm –ivh libjpeg-devel-6b-37.x86_64.rpm 2.
安装jasper-1.900.1.zip (支持JPEG2000)
[plain] view plain copy print ?
- export CFLAGS="-O2 -fPIC"
- ./configure
- make
- make install
export CFLAGS="-O2 -fPIC" ./configure make make install注意:export CFLAGS="-O2 -fPIC" 必须做,否则在make时会报如下错误:
[plain] view plain copy print ?
- /usr/bin/ld:/usr/local/lib/libjasper.a(jas_cm.o): relocation R_X86_64_32 against `a localsymbol' can not be used when making a shared object; recompile with -fPIC
- /usr/local/lib/libjasper.a: could not read symbols: Badvalue
- collect2: ld returned 1 exit status
/usr/bin/ld:/usr/local/lib/libjasper.a(jas_cm.o): relocation R_X86_64_32 against `a localsymbol' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libjasper.a: could not read symbols: Badvalue collect2: ld returned 1 exit status
3. 安装ImageMagick-6.4.0-0.tar.gz
[plain] view plain copy print ?
- tar –zxvf ImageMagick-6.4.0-0.tar.gz
- ./configure -prefix=/usr/local/ImageMagick --enable-shared--without-perl
- make
- make install
tar –zxvf ImageMagick-6.4.0-0.tar.gz ./configure -prefix=/usr/local/ImageMagick --enable-shared--without-perl make make install
下载地址:http://downloads.jmagick.org/6.4.0/ImageMagick-6.4.0-0.tar.gz
注意:安装时若报如下错误:
[plain] view plain copy print ?
- ./magick/xwindow-private.h:27:21: error:X11/Xos.h: No such file or directory
./magick/xwindow-private.h:27:21: error:X11/Xos.h: No such file or directory
则使用yum provides*/Xos.h命令 查看Xos.h所依赖的包,如下所示:
xorg-x11-proto-devel-7.1-13.el5.x86_64 :X.Org X11 Protocol headers
安装所需要的包xorg-x11-proto-devel-7.1-13.el5.x86_64(非常重要),安装完重新make即可
[plain] view plain copy print ?
- yum install xorg-x11-proto-devel-7.1-13.el5.x86_64
yum install xorg-x11-proto-devel-7.1-13.el5.x86_64
4. 安装jmagick-6.4.0-src.tar.gz (java具体路径根据实际情况修改)
下载地址:http://downloads.jmagick.org/6.4.0/jmagick-6.4.0-src.tar.gz
[plain] view plain copy print ?
- ./configure -prefix=/usr/local/jmagick-with-magick-home=/usr/local/ImageMagick
- make all
- make install
./configure -prefix=/usr/local/jmagick-with-magick-home=/usr/local/ImageMagick make all make install
注意:在安装之前请先设置java环境变量
[plain] view plain copy print ?
- export JAVA_HOME=/usr/share/jdk1.6.0_14
- export PATH=$JAVA_HOME/bin:$PATH
- export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME=/usr/share/jdk1.6.0_14 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
否则会报下面错误
[plain] view plain copy print ?
- configure: error: 'Unable to locateJava directories' 或 configure: error: 'No Java headergenerator (javah) found'
configure: error: 'Unable to locateJava directories' 或 configure: error: 'No Java headergenerator (javah) found'
也可以在./configure 时直接指定java安装路径如下所示:
[plain] view plain copy print ?
- ./configure -prefix=/usr/local/jmagick-with-magick-home=/usr/local/ImageMagick -with-java-home=/usr/java/jdk1.6.0_26
./configure -prefix=/usr/local/jmagick-with-magick-home=/usr/local/ImageMagick -with-java-home=/usr/java/jdk1.6.0_26
5. 拷贝libJMagick.so 到/usr/lib下(安装后如果正常生成,则无需执行此步骤)
[plain] view plain copy print ?
- cp/usr/local/jmagick/lib/libJMagick.so /usr/lib
cp/usr/local/jmagick/lib/libJMagick.so /usr/lib
6. 设置ImageMagick和JMagick环境变量 (vi~/.bash_profile)
[plain] view plain copy print ?
- export IM_HOME=/usr/local/ImageMagick
- exportLD_LIBRARY_PATH=/usr/local/lib
export IM_HOME=/usr/local/ImageMagick exportLD_LIBRARY_PATH=/usr/local/lib
注意:修改完后执行 source ~/.bash_profile 让设置立即生效
7. 测试安装是否正常
进入ImageMagick安装目录,cd /usr/local/ImageMagick/bin
[plain] view plain copy print ?
- 执行如下命令,将会在/usr/local/ImageMagick/bin目录生成四张不同格式的logo图片如下:
执行如下命令,将会在/usr/local/ImageMagick/bin目录生成四张不同格式的logo图片如下:
[plain] view plain copy print ?
- convert logo: logo.gif
- convert logo: logo.png
- convert logo: logo.jpg
- convert logo: logo.jpeg
convert logo: logo.gif convert logo: logo.png convert logo: logo.jpg convert logo: logo.jpeg
可以拷贝生成的文件到本地后查看,应该如下图所示,则说明所有安装均正常:
注意:如果在生成jpg时报如下错误:
[plain] view plain copy print ?
- magick.MagickException: Unable to retrievehandle at magick.MagickImage.getDimension(Native Method)
magick.MagickException: Unable to retrievehandle at magick.MagickImage.getDimension(Native Method)
则说明jasper-1.900.1.zip包安装不正确,无法正确处理jpeg2000格式jp2,jpc,需要按照步骤2重新安装。
附录:常见安装问题与说明
1. ImageMagick安装后究竟支持那些格式的文件,可以使用以下命令完成
convert –list configure得到如下图所示:
注意红色箭头那一行代表所支持的文件类型jp2即为jpeg2000
2. 查看支持的文件时也可以使用identify-list format 执行后如图所示,关注箭头部分
3. 命令行测试ImageMagick的缩放功能
convert logo: -resize 100x100resize_logo.png
则会在对应目录生成一张缩小后的图片resize_logo.png
4. 关于magick.MagickException
magick.MagickException: Unable toretrieve handle at magick.MagickImage.getDimension(Native Method)
该异常是因为没有对应的图片处理库造成,是JNI调C++接口时C++代码里抛出,代码如下:
具体代码可参考如下网址:
http://www.hackchina.com/r/8742/JMagick-5.5.6-0-_-src-_-magick-_-magick_ImageInfo.c__html
5. 关于exportCFLAGS="-O2 -fPIC"编译参数
在安装jasper-1.900.1.zip时,若没有指定该参数,后续安装报如下异常:
[plain] view plain copy print ?
- /usr/bin/ld:/usr/local/lib/libjasper.a(jas_cm.o): relocation R_X86_64_32 against `a localsymbol' can not be used when making a shared object;
- recompile with -fPIC/usr/local/lib/libjasper.a: could not read symbols: Badvalue
/usr/bin/ld:/usr/local/lib/libjasper.a(jas_cm.o): relocation R_X86_64_32 against `a localsymbol' can not be used when making a shared object; recompile with -fPIC/usr/local/lib/libjasper.a: could not read symbols: Badvalue
根据提示需要指定fPIC参数后重新编译
注意:在重新编译时一定要清除原来./configure和make时生成的编译文件以及Makefile文件,执行make distclean 即可。
相关软件涉及到的网址:
ImageMagick官网:http://www.imagemagick.org
Jmagick官网:http://www.jmagick.org/index.html
Jasper官网:http://www.ece.uvic.ca/~frodo/jasper/
Jasper官网:http://trac.osgeo.org/gdal/wiki/JasPer
ImageMagick图片解码包地址:ftp://mirror.aarnet.edu.au/pub/imagemagick/delegates/