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.
Mogrify all files in directory, and add suffix.
-
- Posts: 2
- Joined: 2011-07-14T12:38:38-07:00
- Authentication code: 8675308
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Mogrify all files in directory, and add suffix.
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
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.
Code: Select all
for x in *.png
do
root=`echo $x | sed -e "s/.png//"`
convert $x -resize 200x150 ${root}_Resized.png
done
Here's a mogrify command I use sometimes:
Code: Select all
mogrify -resize 200x150 -format PNG *.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Mogrify all files in directory, and add suffix.
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Mogrify all files in directory, and add suffix.
I didn't know morgify -format would replace more than just the suffix! --nice
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Mogrify all files in directory, and add suffix.
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?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Mogrify all files in directory, and add suffix.
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.fmw42 wrote: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_convertanthony wrote:I didn't know morgify -format would replace more than just the suffix! --nice
"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?
Seems I also need a good link to the actual percent escape properties list page there.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 2
- Joined: 2011-07-14T12:38:38-07:00
- Authentication code: 8675308
Re: Mogrify all files in directory, and add suffix.
Brilliant, it worked perfectly. Thank you so much.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