willbeeler
willbeeler

Reputation: 689

How do I batch resize all images to sqares with Image Magick?

OK. I have a horizontal image, let's say 2000 x 300. I want to overwrite that image and create a new one that is 2000 x 2000 with the old image center in the middle and vertically, with white space around it. I also want to do this in batch with many different images of different sizes. Thanks in advance.

Upvotes: 0

Views: 415

Answers (1)

mathematical.coffee
mathematical.coffee

Reputation: 56935

Use -resize to resize the image to 2000x2000, -background to set the background to white, -gravity to center the original image on the canvas, and -extent to resize the canvas itself (to cause the image to sit in the centre if it wasn't square originally).

convert [imagename] -resize 2000x2000 -background white \
                    -gravity center -extent 2000x2000 [imagename]

Upvotes: 1

Related Questions