How can I generate a cropped version of an image without it getting resampled and without priorly knowing the dimensions, and output the url for that in a template?
I need to crop an image to a certain ratio, while retaining the maximum width or height (whichever fits). So not crop to a certain width or height.
For example, let's say I've got three images uploaded:
First is 1000x750 (4:3), second is 750:1000 (3:4), and last one is 2400x800 (3:1).
Now let's say I need images that all have a ratio of 2:1.
First would become 1000x500, second becomes 750:375, and last one becomes 1600x800.
So you see, the first two crop chunks from the top and bottom, reducing their height, while the last ones crops from the sides, reducing its width. No widths or heights are the same in this case, but the ratios are, which is all that matters.
How can I do this?