在Imagemagick for linux中如何进行目录的批量转换

时间:2010-08-19 14:32:31

标签: php linux bash command imagemagick

我希望能够指定扫描位置和转换文件的位置。

只是有很多转换,我有一个脚本应该为我排序。 目前我已经尝试了

convert -resize 300x300 >  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/*.jpg /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$1.jpg

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do  /usr/convert resize 360x360 > /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i done;

3 个答案:

答案 0 :(得分:1)

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do
    convert -resize 360x360 /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i;
done

得到了它!

答案 1 :(得分:1)

如评论所示,您可以使用find命令:

outdir=/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med
cd /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal
find . -iname '*.jpg' -print0 | xargs -I{} -0 -r convert -resize 300x300 {} $outdir/{}

通过使用-print0和xarg的-0选项,这也可以处理带有空格和其他奇数字符的文件名。

答案 2 :(得分:0)

没有理由重复三次长目录。使用变量作为基数。并且不要使用ls

base="/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29"
for file in "$base/normal/*"
do
    convert -resize 360x360 "$file" "$base/tn_med/$(basename $file)"
done

而不是basename你可以这样做:

    convert -resize 360x360 "$file" "$base/tn_med/${file##*/}"