ImageMagick change aspect ratio without scaling the image
Asked Answered
F

1

9

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

Fireside answered 1/4, 2011 at 20:35 Comment(0)
J
13
convert input.png -background white -gravity center -extent 100x300 -flatten output.png

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

Janessa answered 15/4, 2011 at 14:24 Comment(1)
If indeed your image is in PNG format, you can use transparent instead of white, which may be preferable. If the images are photographic, probably should use JPEG, which does not support transparency.Upper

© 2022 - 2024 — McMap. All rights reserved.