2010-08-19 53 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選項,這也處理文件名包含空格和其他奇怪的字符。