Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick change aspect ratio without scaling the image

I have a large number of images that can be any dimension that I need make into the same aspect ratio (basically square). So if one image is 100x300 the output should be 300x300. What I don't want is the image scaled or stretched in any way. I just want a background color (white) applied to the sides of the image, then the original image centered (either vertically or horizontally depending on the original aspect ratio).

I've played around with a couple different convert commands, but I have not found the magic one yet - they all either distort the image to reach the aspect ratio, or scale the image to the correct larger dimension, but do not have the aspect ratio I was looking for.

Thanks in advance

like image 934
John P Avatar asked Apr 01 '11 20:04

John P


People also ask

How do I resize ImageMagick?

To resize an image to specific dimensions, use the convert command with an input file, the -resize parameter, your preferred dimensions, and an output filename: convert original. png -resize 100x100 new. png.

What is XC in ImageMagick?

Yes it is purely an alias for xc: which stood for "X window color", which came from the extreme early days of ImageMagick (long before my time).


1 Answers

convert input.png -background white -gravity center -extent 100x300 -flatten output.png

See http://www.imagemagick.org/Usage/crop/#extent

like image 60
László Németh Avatar answered Oct 15 '22 19:10

László Németh