0
votes

I'd like to add a border to non-square images that will always make them square after resizing.

For example, I start with an image, original.jpg that's 3023x4321:

gm convert -size 3023x4321 xc:blue original.jpg

Ensure the longest dimension is maxed at 800, but I'd like to add a black border around the non-square resized image to ensure the final bordered image is 1000x1000:

gm convert -resize 800x800 -border 220x100 -bordercolor black original.jpg squared.jpg

The problem arises when I have an image with a different aspect ratio. In that case, -border 220x100 won't make the image square.

How can I make the -border flag always give me a square image after resizing and maintain the original aspect ratio?

1
I think -extent is what I need to use: gm convert original.jpg -resize 800 -background black -gravity center -extent 1000x1000 squared.jpgEarthIsHome

1 Answers

0
votes

-extent is better suited than -border to make the image square:

gm convert original.jpg -resize 800 -background black -gravity center -extent 1000x1000 squared.jpg