Page 1 of 1

Use "convert" to get squared images

Posted: 2009-04-13T05:03:00-07:00
by LonelyStar
Hi,

I have a lot of images in a direcotry, some of them landscape format, some of them potrait format.
I want to crop all of them, to get squared images (I need this for useage with metapixel).

I am looking through the crop and shave options of convert, but so for I did not find suitable options for this.
I want all images to be croped in a way, that the maximum big square is taken out and from above and below (or left in right in case of landscape) the same area is cropped away.

Can this be done using convert?

Thanks!
Nathan

Re: Use "convert" to get squared images

Posted: 2009-04-13T09:34:00-07:00
by fmw42
In unix:

size=`convert yourimage -format "%[fx:min(w,h)]" info:`
convert yourimage -gravity center -crop ${size}x${size}+0+0 +repage yourimagecropped

If you are on windows, see http://www.imagemagick.org/Usage/api/#windows


Also see my bash unix script, squareup, at http://www.fmwconcepts.com/imagemagick/index.php

Re: Use "convert" to get squared images

Posted: 2009-04-14T00:47:35-07:00
by anthony
Fred answered this about the best posible way. Their are other solutions if you are resizing the images to a specific size as well, but that is not what you specified.

WARNING if your images are JPEG. DO not save them back to JPEG if you plan to do any further processing. And keep the originals somewhere safe.

Saving to JPEG makes for very small image files, but at the cost of degrading the image, repeatally reading and writing JPEG is NOT recommended. Always restart new image processing from the original source, if at all possible, to ensure you get the highest quality result.