Page 1 of 1
Crop with specific aspect ratio (feature suggestion)
Posted: 2013-02-26T04:44:32-07:00
by bfg9000
Hi.
I miss a feature of cropping with a specific aspect ratio (or I've failed finding it in the docs)
It could work like this
Code: Select all
convert in.png -gravity center -crop 4:3 out.png
and the result would be the file in.png is cropped to a ratio 4:3 (keeping as much as possible of the original file).
Looking forward to seeing this in the next version
Re: Crop with specific aspect ratio (feature suggestion)
Posted: 2013-02-26T10:40:58-07:00
by fmw42
you can do that now by computing the Width and Height to satisfy your aspect ratio and then using just crop WxH+0+0 +repage.
The issue you must consider which contributes to the coding is which dimension to use to compute the aspect ratio so that you can crop and not need to pad. Thus you may need to compute the aspect ratio of the input image and compare it to the desired aspect ratio.
for unix see my scripts, aspect and aspectpad, thought they do not do exactly what you want.
Re: Crop with specific aspect ratio (feature suggestion)
Posted: 2013-02-26T10:51:44-07:00
by magick
Try -crop 100%x75%+0+0.
Re: Crop with specific aspect ratio (feature suggestion)
Posted: 2013-04-04T23:22:21-07:00
by anthony
I would have though that only works for square input images...
In IMv7 you can use %[fx:...] expressions directly in -crop, or better still -extent (which can crop or pad an image to fit the calculated size).
In IMv6 you can fudge it using a distort viewport...
For example see IM Examples, Centered Square Crop
http://www.imagemagick.org/Usage/distor ... red_square
This is for the largest 1:1 crop you can get from an image. But should be able to calculate a largest 4:3 ratio crop with minimal changes.
Anyone like to give it a go... Results can be added to the above area of IM examples with your name.
Re: Crop with specific aspect ratio (feature suggestion)
Posted: 2013-08-04T02:06:16-07:00
by GreenKoopa
I was going to create this example, but after some thought it doesn't seem too useful. First, the OP sets gravity, which -distort doesn't use. Your square example assumes a gravity of center. Second, the solution is less well defined when not a square. If the input image is 90x100 and 4:3 is requested, what is the output dimensions desired? 90x68 is a 4:3.02 ratio and 90x67 is a 4:2.98 ratio. Or is a 88x66 output better? Maybe the user didn't intend to impose an orientation, so 75x100 is best?
Your square example shows the concept. A user could easily adapt that to their well-defined need.
Re: Crop with specific aspect ratio (feature suggestion)
Posted: 2013-08-04T10:52:49-07:00
by fmw42
I have a bash unix script, aspectpad, that pads to the desired aspect ratio. I also have a script, aspect, that will either crop or pad, but it includes a resize. So you would need to specify the aspect widthxheight so as not to resize. See the link below. Neither do exactly what you want, but may be close enough for your needs.