Page 1 of 1

Mogrify all files in directory, and add suffix.

Posted: 2011-07-14T12:42:57-07:00
by akobylarek
Version: 6.71-0
Unix

I am trying to resize all pngs in a directory, there a couple hundred so I don't really want to do it by hand.

I want to keep the old files, and I want the new files to append a suffix on the end.

TempImage.png creates TempImage_Resized.png

Any help on how to do this would be greatly appreciated.

Re: Mogrify all files in directory, and add suffix.

Posted: 2011-07-14T14:01:21-07:00
by fmw42
the closest I can come is to create two directories: tmp1 has the images and tmp2 is empty

cd tmp1
mogrify -path /Users/fred/tmp2/ -format "Resized.png" -resize 50% *.png

The results will be originalimagename.Resized.png and placed in tmp2. (or leave off the path and they will end up in tmp1)


see mogrify at
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_convert
http://www.imagemagick.org/Usage/basics/#mogrify_not

Re: Mogrify all files in directory, and add suffix.

Posted: 2011-07-14T14:16:21-07:00
by glennrp
    This uses convert, not mogrify, but it should work on Unix/Linux:

    Code: Select all

    for x in *.png
    do
    root=`echo $x | sed -e "s/.png//"`
    convert $x -resize 200x150 ${root}_Resized.png
    done
    The back-ticks ( ` ) are hard to see in the listing; don't omit them!

    Here's a mogrify command I use sometimes:

    Code: Select all

    mogrify -resize 200x150 -format PNG *.png
    In this example the original files are filename.png and the thumbnails are filename.PNG

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-14T14:22:57-07:00
    by fmw42
    Here is an improvement that gets what you want.


    cd /Users/fred/tmp1
    mogrify -path /Users/fred/cyclops2/ -format "_Resized.jpg" -resize 50% *.png
    cd /Users/fred/tmp2
    filelist=$(ls)
    for file in $filelist; do
    mv "$file" "$(echo "$file" | sed 's/._/_/g' )"
    done

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-14T18:05:55-07:00
    by anthony
    I didn't know morgify -format would replace more than just the suffix! --nice

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-14T18:37:26-07:00
    by fmw42
    anthony wrote:I didn't know morgify -format would replace more than just the suffix! --nice

    Neither did I until I experimented. But I was puzzled and unable to achieve any results using %o as you discussed at http://www.imagemagick.org/Usage/basics ... fy_convert

    "Mogrify itself could modify the filename (using "-format" and "-path" settings) to generate a new filename accessable as '%o', in "convert" that is the same as the '%i' escape."

    can you provide a working example? have I misunderstood what you are trying to say here?

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-14T19:14:22-07:00
    by anthony
    fmw42 wrote:
    anthony wrote:I didn't know morgify -format would replace more than just the suffix! --nice
    Neither did I until I experimented. But I was puzzled and unable to achieve any results using %o as you discussed at http://www.imagemagick.org/Usage/basics ... fy_convert

    "Mogrify itself could modify the filename (using "-format" and "-path" settings) to generate a new filename accessible as '%o', in "convert" that is the same as the '%i' escape."

    can you provide a working example? have I misunderstood what you are trying to say here?
    Hmm I'm a little puzzled myself looking back on it. I'll remove that comment for now form IM examples, at least until it comes back to me, and I can write it more distinctly.

    Seems I also need a good link to the actual percent escape properties list page there.

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-14T20:11:13-07:00
    by fmw42

    Re: Mogrify all files in directory, and add suffix.

    Posted: 2011-07-15T21:13:31-07:00
    by akobylarek
    fmw42 wrote: cd /Users/fred/tmp1
    mogrify -path /Users/fred/cyclops2/ -format "_Resized.jpg" -resize 50% *.png
    cd /Users/fred/tmp2
    filelist=$(ls)
    for file in $filelist; do
    mv "$file" "$(echo "$file" | sed 's/._/_/g' )"
    done
    Brilliant, it worked perfectly. Thank you so much.