安装依赖包:

yum install libpng libjpeg freetype libpng-devel libjpeg-devel libtool-ltdl-devel libtool-ltdl

官网下载GraphicsMagick包

官网地址:http://www.graphicsmagick.org/


解压编译安装:

tar xf GraphicsMagick-1.3.25.tar.gz

./configure --prefix=/usr/local/graphicsmagick-1.3.25 --enable-shared --enable-lzw --without-perl --with-modules

make && make install


附图片批量处理脚本:

#!/bin/bash
IFS=`echo -en "\n\b"`;
echo $IFS
function geneThumb()
{
for file in `ls $1`
do
echo $file
p_w_picpath="${1}/${file}"
thumb="${1}/Thumb_${file}"
        ext_name=${file##*.}
        p_w_picpath_basename=`basename $p_w_picpath`
if [ -d ${p_w_picpath} ]
then
geneThumb ${p_w_picpath}
elif ( [ ${p_w_picpath_basename:0:5} != "Thumb" ]) && ( [ ! -f ${thumb} ] ) &&  ( [ $ext_name = 'jpg' -o $ext_name = 'gif' -o $ext_name = 'png' -o $ext_name = 'bmp' ] )
then
echo $thumb
                if [ $ext_name = 'png' -o $ext_name = 'bmp' ]
                then
                    gm convert "$p_w_picpath" -thumbnail 128x128 -colors 256 "$thumb"
                else
                    gm convert "$p_w_picpath" -thumbnail 128x128 -quality 85 "$thumb"
                fi
else
echo "already exists"
fi
done
}
geneThumb $1