Resize and pad instead of stretch

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
daviddoria

Resize and pad instead of stretch

Post by daviddoria »

If I do this:

Code: Select all

convert File.jpg -resize 100x100\! Output.jpg
It will result in a 100x100 image, but if the aspect ratio has changed, the image will be stretched to fit the new ratio. Is there anyway to say "reduce so one of the dimensions to fits the aspect ratio, and pad with black (or white or something else) so that the picture is not stretched"?

Thanks,

Dave
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Resize and pad instead of stretch

Post by Bonzo »

You want to use -extent:

Code: Select all

convert img1b.jpg -resize 100x100 -background black -gravity center -extent 100x100 david.png
daviddoria

Re: Resize and pad instead of stretch

Post by daviddoria »

perfect, thanks!
Post Reply