For resizing, we can tell IM to resize if an image is larger than a given size. Is it possible for crop (gravity) too?
I want to prepare images for instagram, which apparently has limitations for aspect ratio:
Landscape: 1.91:1
Portrait: 4:5
Can I tell IM to crop only if the image is beyond these aspect ratios?
How to crop by aspect ratio?
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: How to crop by aspect ratio?
You should always include the version of IM you're using and which platform you're running it on.
With most recent versions you can crop to a particular aspect ratio using "-extent" like this...
Code: Select all
magick input.png -gravity center -extent 1.91:1 result.png
Re: How to crop by aspect ratio?
It works beautifully.
Anyhow, my version is ImageMagick 7.0.8-34 on Ubuntu.
Anyhow, my version is ImageMagick 7.0.8-34 on Ubuntu.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to crop by aspect ratio?
Thanks, GeeMack. I though there was an operation for this, but forgot what it was.
@Fred: Can we update http://www.imagemagick.org/script/comma ... php#extent to note this syntax, please?
@Fred: Can we update http://www.imagemagick.org/script/comma ... php#extent to note this syntax, please?
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to crop by aspect ratio?
Not that I know. You will have to test the aspect ratios before hand.Can I tell IM to crop only if the image is beyond these aspect ratios?
You can also do
Code: Select all
magick input.png -gravity center -crop 1.91:1+0+0 +repage result.png
Code: Select all
magick input.png -gravity center -crop 1.91:1+0+0\> +repage result.png