FUrn wrote: ↑2018-10-30T09:53:59-07:00I'd imagine I need to adjust the canvas to this new size (using white background), and ensure the original image is centered in the new canvas. Is this possible on ImageMagick?
This command will take any input image and pad it with white as necessary to create a square output image. If the input is wider than high, it will pad the top and bottom while centering the input in the square. If it's higher than wide, it will pad the left and right so the input is centered in the square output. If the input is already square it will leave the dimensions unchanged.
Code: Select all
convert input.png -virtual-pixel white ^
-set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]" ^
-distort affine "0,0 %[fx:w<h?(h-w)/2:0],%[fx:w>h?(w-h)/2:0]" result.png
That uses IM6 and is in Windows syntax. For IM7 use "magick" instead of "convert". To put it in a Windows BAT script, double the percent signs "%%". To run it as a *nix shell command, replace those end-of-line carets "^" with backslashes "\".
Note that if you're using IM version 7, the example command
snibgo provided above is a much more straightforward approach.
Either way, to perform this sort of operation on multiple files it's probably best to use a "for" loop as
snibgo suggested. The syntax depends on the platform you're running on.