edit: End goal is a 2:1 aspect ratio, no cropping, and a max size of 1260x630. If the image dimensions are originally below 1260x630, they should stay below 1260x630.
Struggling to word this well (which very well may be the reason I haven't found a good answer).
With ImageMagick I'm trying to resize an image down to 1260x630 provided the image itself is larger than the given size (width OR height).
Once resized I need to change the aspect ratio to a 2:1 without cutting off the image. I've accomplished this well enough with larger images using the following:
convert foobar-original.jpg \
-resize 1260x630\> \
-gravity center \
-extent 1260x630 \
foobar.jpg
A 1500x500 picture, for example, using the above, becomes first 1260x420 (with the resize) and then 1260x630 (via the extent), and the extra width is filled in with white background.
However, if the image starts off smaller, 800x200 for example, the image is not resized (as expected) but then is made to fit within a full 1260x630. This is not the desired result.
I would rather -extent
simply affect the aspect ratio, adding on white as needed. So rather than the 800x200 image converting to 1260x630, with the 800x200 part of the image in the center, I would like the image to be converted to 800x400 (that 2:1 ratio), the extra height filled in with white space.
Basically, I'm looking for a way to set -extent
to an aspect ratio, rather than a specific size or percentage. Something like
convert foobar-original.jpg \
-resize 1260x630\> \
-gravity center \
-extent 2:1 \
foobar.jpg