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
Use "convert" to get squared images
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Use "convert" to get squared images
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Use "convert" to get squared images
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/