Auto adjust photos into preset boundaries

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jarhar

Auto adjust photos into preset boundaries

Post by jarhar »

I create random sized image files (usually from screen and document clippings) that need to converted so that they are no larger than 400x220. Is there a way that ImageMagick can automatically adjust the sizes of the files so that they will fit into the 400x220 space? I don't want them cropped, just the whole things sized down to fit within 400x220.

Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto adjust photos into preset boundaries

Post by fmw42 »

-resize "400x220!" will force the image to exactly that size, but you may get distortion as it won't preserve aspect ratio

-resize 400x220 will resize the larger dimension of the image to fit one or the other parameter as appropriate and the other image dimension will be smaller than the other argument

see http://www.imagemagick.org/script/comma ... p#geometry
jarhar

Re: Auto adjust photos into preset boundaries

Post by jarhar »

Awesome, thanks, the second option is just what I need. What would be the easiest way for me to implement ImageMagick for doing this? Could I put all the images needing this done into a folder and run ... -resize 400x220 *.* and have it do all in the folder at once? Or what would be the easiest (fastest) way? For one at a time and for groups?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto adjust photos into preset boundaries

Post by fmw42 »

I would create a second empty directory for safety in case something goes wrong and write the results using mogrify to that directory. It will do all files in a directory. For example, create directory test1 with your images and directory test2 that is empty.

cd /fullpathto/test1
mogrify -path /fullpathto/test2 -format jpg -resize WidthxHeight *.*

will convert any filetype to jpg while reducing the images

or

mogrify -path /fullpathto/test2 -format jpg -resize WidthxHeight *.png

will convert only png to jpg while reducing the images


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

Re: Auto adjust photos into preset boundaries

Post by jarhar »

Great solution. I'm looking forward to getting it set up (probably a little script and a shortcut to the script) and using it. Thanks a lot for your help.
Post Reply