2016-10-28 2 views
1

나는 응용 프로그램의 아이콘 컨텍스트를 생성하는 OSX 맥에서 .sh로를 가지고,하지만 난 스크립트를 실행할 때 나는 메시지를 폴더맥에서 강타와 이미지 매직

에서

convert: unable to open image `c.png': No such file or directory @ error/blob.c/OpenBlob/2709. 
convert: unable to open file `c.png' @ error/png.c/ReadPNGImage/3917. 
convert: no images defined `mipmap-mdpi/c.png' @ error/convert.c/ConvertImageCommand/3210. 

및 파일 c.png 체류를 얻을 수

read original 
read nombre_resultante 
read size 


Resize() { 

    if [ "$size" == "1" ]; then 
    SIZE_MDPI="48x48" 
    SIZE_HDPI="72x72" 
    SIZE_XHDPI="96x96" 
    SIZE_XXHDPI="144x144" 
    SIZE_XXXHDPI="192x192" 
    elif [ "$size" == "2" ]; then 
    SIZE_MDPI="24x24" 
    SIZE_HDPI="36x36" 
    SIZE_XHDPI="48x48" 
    SIZE_XXHDPI="72x72" 
    SIZE_XXXHDPI="96x96" 
    fi 

    rm -rf mipmap-mdpi/* 
    rm -rf mipmap-hdpi/* 
    rm -rf mipmap-xhdpi/* 
    rm -rf mipmap-xxhdpi/* 
    rm -rf mipmap-xxxhdpi/* 

    convert $original -resize "$SIZE_MDPI" mipmap-mdpi/$nombre_resultante 
    convert $original -resize "$SIZE_HDPI" mipmap-hdpi/$nombre_resultante 
    convert $original -resize "$SIZE_XHDPI" mipmap-xhdpi/$nombre_resultante 
    convert $original -resize "$SIZE_XXHDPI" mipmap-xxhdpi/$nombre_resultante 
    convert $original -resize "$SIZE_XXXHDPI" mipmap-xxxhdpi/$nombre_resultante 
} 

Resize $size 
+1

는 당신에게 파일이 존재 확신? 명령을 실행하기 전에 bash에서 사전 점검 할 수 있습니다. 그리고 $ size 인자는'Resize'를 호출 할 때 쓸모가 없습니다. –

답변

1

오류 메시지는 c.png 파일이 없음을 의미합니다. 나는 존재하지 않는 파일을 사용하여 오류 메시지를 재현 할 수 있습니다 : 당신이 스크립트를 실행할 때

$ convert nonexistent.png -resize 48x48 a/b/whatever.png 
convert: unable to open image `nonexistent.png': No such file or directory @ error/blob.c/OpenBlob/2702. 
convert: unable to open file `nonexistent.png' @ error/png.c/ReadPNGImage/3913. 
convert: no images defined `a/b/whatever.png' @ error/convert.c/ConvertImageCommand/3241. 

은 아마 잘못된 디렉토리에 있습니다. cd을 파일이있는 올바른 디렉토리에 저장하고 서브 디렉토리 mipmap-*dpi이있는 곳에 복사하십시오.

이 같은 크기 조정 함수를 호출하기 전에 검사를 추가 할 수 있습니다

if [ ! -f "$original" ]; then 
    echo fatal: file does not exist: $original 
    exit 1 
fi