2012-06-14 21 views
1

我有兩個圖像。我創建了一個用於處理它的.sh文件。首先,我用一個for循環的..在Ubuntu的shell腳本中調整圖片大小

我的導演結構: -

測試 圖像0​​DOC newimage angelimage test.sh 5elements10.png boltonclinics5.png

現在我想要2個圖像複合一個3rd.png都存儲在newimage之後,我希望在newimage文件夾中的圖像轉換爲一個特殊的天使。 所以我儘量用代碼

#!/bin/bash 
for f in $(ls *.png); do 
    composite -gravity center $f ./doc/back.png ./newimage/new$f 
done 
for f in `ls ./newimage`; do 

    convert $f -rotate -7 ./angelimage/ang$f 
done 

現在我發現,for循環正常工作,但第二個給出瞭如下的錯誤波紋管

convert: unable to open image `new-5elements10.png': @ error/blob.c/OpenBlob/2587. 
convert: unable to open file `new-5elements10.png' @ error/png.c/ReadPNGImage/3234. 
convert: missing an image filename `new-5elements10.png' @ error/convert.c/ConvertImageCommand/3011. 
convert: unable to open image `new-boltonclinics5.png': @ error/blob.c/OpenBlob/2587. 
convert: unable to open file `new-boltonclinics5.png' @ error/png.c/ReadPNGImage/3234. 
convert: missing an image filename `new-boltonclinics5.png' @ error/convert.c/ConvertImageCommand/3011. 

回答

-1

不要使用ls(1)生產提供給命令的文件列表。簡單的glob擴展就足夠了(如下所示)。

引用您的變量以防止空白問題。

如果沒有在你的代碼的任何其它邏輯上的錯誤,這應該工作:

#!/bin/bash 

for f in *.png; 
do 
    composite -gravity center "$f" ./doc/back.png "./newimage/new${f}" 
done 

for f in ./newimage/*; 
do 
    convert -rotate -7 "$f" "./angelimage/ang$(basename "$f")" 
done 
+0

轉換「$ F」 -rotate -7「./a​​ngelimage/ang${f}」不工作如前所述。當我添加ls $ f它的作品,但不工作上述代碼 – Rain

+0

我編輯了第二個循環,轉換語法是錯誤的。 – tvm

+0

現在我添加這個用於將兩個圖像保存在一個名爲finalimage的新文件夾中,最後一個for loop for f用於./newimage/*; do convert -rotate -7「$ f」「./angelimage/a$(basename」$ f「)」 echo $ f; composite-geometry + 200 + 130「$ f」「./angelimage/a$(basename」$ f「)」「./finalimage/final${f}」 done,但沒有工作 – Rain