batch resizing
-
- Posts: 1
- Joined: 2012-02-08T17:46:16-07:00
- Authentication code: 8675308
batch resizing
I am using imagemagick under ubuntu. What algorithm would I use to resize all images in a directory to a resolution of 640x385, but ONLY if they have a resolution of 320x240.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: batch resizing
mogrify has the ability to resize all images in a folder, but I don't believe you can restrict it to a particular size.
You can probably do one of two things.
1) Write a bash shell script to check the image size and then resize the ones you want.
2) Write a script to find the images of the size you want and then feed those to mogrify to do the resize.
See
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics/#mogrify_not
You can extract the image size from any image using string formats:
http://www.imagemagick.org/script/escape.php
for example
size=`convert image -format "%wx%h" info:`
using the IM internal image logo:
size=`convert logo: -format "%wx%h" info:`
echo "$size"
640x480
You can probably do one of two things.
1) Write a bash shell script to check the image size and then resize the ones you want.
2) Write a script to find the images of the size you want and then feed those to mogrify to do the resize.
See
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics/#mogrify_not
You can extract the image size from any image using string formats:
http://www.imagemagick.org/script/escape.php
for example
size=`convert image -format "%wx%h" info:`
using the IM internal image logo:
size=`convert logo: -format "%wx%h" info:`
echo "$size"
640x480
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: batch resizing
I would use a pipeline...
the identify lists the filename and size of all images
the sed looks for a specific size and removes the size leaving just the filename
the xargs command reads filenames, quotes them and added them to the end of the given command, "mogrify" in this case.
results is that only images with the matching sized are found and resized.
TEST thoroughly!
PS: using "xargs" is in the "mogrify_not" section of IM Examples, but using a '-I' option to make it run one command on each individual file "convert", rather than 'batch' multiple files in one command. Read its manpage.
A alternative is "parallel" from GNU which is a paralleling (run multiple command simultaneously) version of "xargs"
Code: Select all
identify -format '%f %wx%h' images... | sed -n 's/ 320x240$//p' | xargs mogrify -resize 640x385\!
the sed looks for a specific size and removes the size leaving just the filename
the xargs command reads filenames, quotes them and added them to the end of the given command, "mogrify" in this case.
results is that only images with the matching sized are found and resized.
TEST thoroughly!
PS: using "xargs" is in the "mogrify_not" section of IM Examples, but using a '-I' option to make it run one command on each individual file "convert", rather than 'batch' multiple files in one command. Read its manpage.
A alternative is "parallel" from GNU which is a paralleling (run multiple command simultaneously) version of "xargs"
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/