Forum
Get aspect ratio of image
Is it possible to get the aspect ratio of an image?
I would like to use it for sizing images with flex box.
Is it possible to get the aspect ratio of an image?
I would like to use it for sizing images with flex box.
You can get the width and height, so I think you could write a template filter to calculate the ratio.
I'd need to return a figure such as 1.45. It's for flex box to size the images within their parent to fill the space while having equal heights.
It can be done with js, buts it's a bit flaky.
Hello Tony,
Like Drew suggested, you can access the image's width and height in a template filter so you can do the maths in PHP. To learn more about writing a template filter: https://docs.grabaperch.com/api/template-filters/