Keeping an image squared

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
thes4s67
Posts: 3
Joined: 2015-10-05T08:37:22-07:00
Authentication code: 1151

Keeping an image squared

Post by thes4s67 »

Hi everyone. I am using imagemagick to batch trim a set of images to remove whitespace with the following command:

Code: Select all

mogrify -trim -fuzz 5 *.jpg
This works fine however how do I get the output image size to be squared? The images vary so there can't be a set squared size. I also saw this viewtopic.php?t=10419 which is quite similar to my request but I can't seem to figure out how to use those commands in addition to my command.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Keeping an image squared

Post by snibgo »

"-trim" will create a rectangular image. You want to make this square. How? You can crop it with "-crop". Or add transparent portions to make it square with "-background None -extent 200x200". In either case, it's easiest with two commands: "identify" to get the max or min dimension, then "convert" to crop or extent.

The third method, which you probably don't want, is to resize, changing the aspect ratio.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Keeping an image squared

Post by fmw42 »

Post Reply