#!/usr/bin/perl
$identify= "/usr/local/ImageMagick/bin/identify";
$convert= "/usr/local/ImageMagick/bin/convert";
$composite= "/usr/local/ImageMagick/bin/composite";
$convdir= "./pics"; #源路径
$objcdir= "./picd"; #目标路径
$tmp= "/tmp/.conv.tmp";
$white= "/root/white.jpg";
opendir(OD,$convdir);
@allds=readdir OD;
closedir OD;
foreach $alldf(@allds){
if($alldf ne "." && $alldf ne ".."){
system("$convert $convdir/$alldf -resize 100x100 $tmp");
open(SO,"$identify $tmp|");
$allso=<SO>;
close SO;
@alls=split(/ +/,$allso);
@wh=split(/x/,$alls[2]);
$wh[1]=~s/\+[0-9]//g;
if($wh[0]>$wh[1]){
$offset=(100-$wh[1])/2;
system("$composite -geometry +0+$offset $tmp $white $objcdir/$alldf");
}else{
$offs=(100-$wh[0])/2;
system("$composite -geometry +$offset+0 $tmp $white $objcdir/$alldf");
}
}
}
这段代码的作用,是把"源路径"里的所有图片,转换成不大于100x100的缩略图片,然后加上背景(white.jpg),保存在"目标路径里"
关键是 有这个:gif源图缩小了还是动态的
convert 1-8-51-32-357532324.gif -resize 50x50 ysl.gif
本文地址:http://com.8s8s.com/it/it30903.htm