graphicsmagick

In graphicsmagick, how can I specify the output file on a bulk of files?


I want to convert a group of files, but not overwrite the existing file. How can I use mogrify to specificy the final file format? For example, firstpic.png -> firstpic-thumbnail.png, secondpic.png -> secondpic-thumbnail.png, etc.

gm mogrify -size 150x150 *.png -resize 150x150 +profile "*" "%f-thumbnail.png"

Is there any way to do this?


Solution

  • I don't know if there's a way to specify output file format from mogrify but I would use convert with simple bash loop instead:

    for f in *.jpg; 
    do 
        convert "$f" -resize 150x150 +profile "*" "${f%.jpg}-thumbnail.jpg"; 
    done;
    

    Or if you really want to use mogrify you can use -output-directory (more on this option here) to put new files into separate directory and then take care of renaming:

    mkdir tmp;
    gm mogrify -output-directory tmp -size 150x150  -resize 150x150 +profile "" "*.jpg";
    for f in tmp/*.jpg; 
    do 
        mv "$f" "${f%.jpg}-thumbnail.jpg"; 
    done;
    mv tmp/* .;
    rm -rf tmp;
    

    I like the first method better ;)