2010-08-19 54 views
1

我希望能够在哪里扫描以及转换后的文件将在哪里指定位置。在Imagemagick for linux中如何对目录进行批量转换

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

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; 
+1

您是否尝试过寻找到Linux'find'命令?特别是'-exec'选项? – ircmaxell 2010-08-19 14:36:49

回答

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##*/}" 
+0

感谢你们两位的帮助。我希望他们通过php exec命令工作 - 但他们应该.. 感谢关于奇怪字符的评论 - 不应该有,但情况总是如此。 – 2010-08-23 09:21:20

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 

得到它!

+0

这不会处理包含空格的文件名。 – 2010-08-19 15:01:50

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选项,这也处理文件名包含空格和其他奇怪的字符。