ImageMagick是一个专业的图像处理包,提供C写的命令、C/C++ API。Fred's ImageMagick Script在其基础上,用shell脚本调用这些C的命令,搭配出种类繁多的图像处理特效,每一种特效用一个shell脚本实现,有详细的命令使用和参数说明,并在主页上配有示例效果图,其运行效果一目了然。
1)进入这里,找个入口,如这里,下载最新的ImageMagick包,如 ImageMagick-6.8.4-10.tar.gz
2)解压,进入解压后的目录
3)配置,编译,安装:
./configure \
--with-modules=yes --with-bzlib=yes \
--with-dejavu-font-dir=default \
--with-fftw=yes \
--with-gvc=yes \
--with-jp2=yes \
--with-lcms=yes \
--with-lcms2=yes \
--with-openexr=yes \
--with-perl=yes \
--with-rsvg=yes \
--with-wmf=yes \
--with-x=yes \
--with-xml=yes \
--with-autotrace=yes \
--with-gslib=yes \
--with-gvc=yes
make // 生成的命令在 ./utilities 和 ./utilities/./libs 中
make install // binary默认安装到 /usr/local/bin 中,库文件默认安装到 /usr/local/lib 中,头文件在/usr/local/include/ImageMagick-6 中
A)试用denoise脚本
1) 在这里点击"Download script"下载denoise脚本,下载带噪声的 lena 图片,另存为 lena_noise.jpg
2) chmod +x denoise
3) denoise lena_noise.jpg
4) ./denoise -f 2 -s "20x20+203+152" -m mean lena_noise.jpg lena_denoised.jpg
A)试用命令
convert -negate lena_denoised.jpg lena_converted.jpg
可以看到去噪后的效果: lena_denoised.jpg,和 反色后的效果:lena_converted.jpg
lena_noise
lena_denoised
lena_converted
1)如果configure提示“configure: error: libltdl is required for modules build”,则yum search ltdl,然后(以CentOS 6.3 64bit 为例)
yum install libtool-ltdl.x86_64
yum install libtool-ltdl-devel.x86_64
2)在make之前,如果./configure不带任何参数,可能会在后面执行脚本时,遇到类似下面的问题,所以建议./configure时带上必要的参数项。
convert: no decode delegate for this image format `./logo.png' @ error/constitute.c/ReadImage/550.
convert: no images defined `./accentedges_A_14320.mpc' @ error/convert.c/ConvertImageCommand/3103.
--- FILE ./logo.png DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---
convert: unable to open image `./accentedges_A_14320.mpc': No such file or directory @ error/blob.c/OpenBlob/2641.
convert: image sequence is required `-clone' @ error/convert.c/ConvertImageCommand/941.
源码解压路径下的 Install-unix.txt 文件提到,在执行 ./configure 命令之后,要留意控制台输出的最后几行,看看configure命令是否找到了所有我们想要的东西,即,如果没有的话,在configure命令中加入缺失的参数项。下面是 Install-unix.txt 文件给出的一个标准配置,供参考:
ImageMagick is configured as follows. Please verify that this configuration
matches your expectations.
Host system type: x86_64-unknown-linux-gnu
Build system type: x86_64-unknown-linux-gnu
Option Value
----------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Module support --with-modules=yes yes
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no
Delegate Configuration:
BZLIB --with-bzlib=yes yes
Autotrace --with-autotrace=yes yes
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=yes yes
FreeType --with-freetype=yes yes
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (8.63)
result_ghostscript_font_dir='none'
Ghostscript fonts --with-gs-font-dir=default
Ghostscript lib --with-gslib=yes no (failed tests)
Graphviz --with-gvc=yes yes
JBIG --with-jbig= no
JPEG v1 --with-jpeg=yes yes
JPEG-2000 --with-jp2=yes yes
LCMS v1 --with-lcms=yes yes
LCMS v2 --with-lcms2=yes yes
LQR --with-lqr=yes no
Magick++ --with-magick-plus-plus=yesyes
OpenEXR --with-openexr=yes yes
PERL --with-perl=yes /usr/bin/perl
PNG --with-png=yes yes
RSVG --with-rsvg=yes yes
TIFF --with-tiff=yes yes
result_windows_font_dir='none'
Windows fonts --with-windows-font-dir=
WMF --with-wmf=yes yes
X11 --with-x= yes
XML --with-xml=yes yes
ZLIB --with-zlib=yes yes
X11 Configuration:
X_CFLAGS =
X_PRE_LIBS = -lSM -lICE
X_LIBS =
X_EXTRA_LIBS =
Options used to compile and link:
PREFIX = /usr/local
EXEC-PREFIX = /usr/local
VERSION = 6.4.8
CC = gcc -std=gnu99
CFLAGS = -fopenmp -g -O2 -Wall -W -pthread
MAGICK_CFLAGS = -fopenmp -g -O2 -Wall -W -pthread
CPPFLAGS = -I/usr/local/include/ImageMagick
PCFLAGS = -fopenmp
DEFS = -DHAVE_CONFIG_H
LDFLAGS = -lfreetype
MAGICK_LDFLAGS = -L/usr/local/lib -lfreetype
LIBS = -lMagickCore -llcms -ltiff -lfreetype -ljpeg
-lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz
-lm -lgomp -lpthread -lltdl
CXX = g++
CXXFLAGS = -g -O2 -Wall -W -pthread
3)运行IM命令时,如果出现下面的错误时,
“error while loading shared libraries:xxx.so.1找不到”
请这样做:
在 /etc/ld.so.conf 中加入一行:/usr/local/lib,然后执行 /sbin/ldconfig -v,让新加的路径生效
4)即使在configure命令后加了某些参数,比如--with-tiff=yes,但configure出来的report中,tiff的value项还是no,这说明当前机器缺少相应的“delegate”,比如tiff的开发库,这时就要到http://www.imagemagick.org/download/delegates/ 上去下载并安装这些库。但是并不是所有的库在那个页面上都能找得到……
如果是Ubuntu上build,也可以在执行configure之前,执行 apt-get build-dep libmagick++-dev,之后下面的库就会被支持:
BZLIB, DJVU, FFTW, JBIG, JPEG-2000, LCMS v2, LQR, LZMZ, TIFF, WMF
但是仍然还有一些不被支持,包括:
Autotrace, DPS, FlashPIX, Ghostscript lib, Graphviz, LCMS v1, MUPDF, OpenEXR, WEBP, Windows fonts