Page 1 of 1

Resize to a fixed geometry but maintain aspect ratio

Posted: 2008-11-25T11:24:27-07:00
by smithmarkl
Hello,

I need to convert an image from the command line to a fixed sized, but maintain the aspect ratio of the image content. This gets me close:
convert -resize 256x256 infile.jpg outfile.jpg

The problem being that I end up with one dimension that is less than 256 pixels. What I need is to fill in that space with black or transparent pixels above and below the image content to bring that dimension up to 256 pixels.

Any ideas on command line arg combinations to try?

Re: Resize to a fixed geometry but maintain aspect ratio

Posted: 2008-11-25T12:33:47-07:00
by fmw42
smithmarkl wrote:Hello,

I need to convert an image from the command line to a fixed sized, but maintain the aspect ratio of the image content. This gets me close:
convert -resize 256x256 infile.jpg outfile.jpg

The problem being that I end up with one dimension that is less than 256 pixels. What I need is to fill in that space with black or transparent pixels above and below the image content to bring that dimension up to 256 pixels.

Any ideas on command line arg combinations to try?

see my tidbits page http://www.fmwconcepts.com/imagemagick/ ... ize_square

Re: Resize to a fixed geometry but maintain aspect ratio

Posted: 2008-11-25T14:45:02-07:00
by smithmarkl
That was very helpful. This does the trick:
convert -resize 256x256 infile.jpg -background none -gravity center -extent 256x256 outfile.jpg

Re: Resize to a fixed geometry but maintain aspect ratio

Posted: 2008-11-25T15:47:45-07:00
by anthony
Generally this is know and thumbnail padding
http://www.imagemagick.org/Usage/thumbnails/#pad

Also please start reading the image before working on it, or you will have problems in the future.

EG: convert {read options} image {conversion operators} save_image