The aspect ratio of an image is the ratio of its width to its height, and is expressed with two numbers separated by a colon, such as 16:9, sixteen-to-nine. For the x:y aspect ratio, the image is x units wide and y units high.
In Cloudinary, we use aspect ratio to conform the cropping or resizing transformation to a ratio. For example, `ar_<ratio value>` can be used with (`c_crop` or `c_fill`) and, optionally, in combination with `h_` or `w_`.
The transformation reference page, provides excellent reference and examples. One obvious use case is to create a portrait crop to a horizontal image. This image features a girl resting on the ground with a red bicycle next to her. We can tell that the image is horizontal with an aspect ratio of 3:2. Where width's length being 1 unit more than the height. How can we create a crop image where we only take her face and set it as a portrait aspect ratio (height being larger than the width)? With a combination of `g_face` (gravity face) transformation, this is easily done with the following transformation:
https://res.cloudinary.com/demo/image/upload/g_face,c_crop,h_600,ar_9:16/samples/bike.jpg
With the example above, we effectively tell the transformation to crop in a portrait shape by adding the `ar_9:16` along side the `c_crop`. Because we supply the height to be `h_600`, the crop transformation will base its cut on the height and appropriately proportion the width based on the guideline of 9:16 aspect ratio.
Comments
0 comments
Please sign in to leave a comment.