How to get image metadata of resized image?

Hi everyone,

I have a use case that I can’t seem to find a solution for. I’m trying to get the dimensions of an image that I have resized using resize_image with a given width and an op of fit_width so the height is derived from the original aspect ratio of the image. After doing this, I’d like to inspect the image so I can specify the dimensions of the image in HTML. I would like to do something like this:

{% set resized_image = resize_image(path = page.path ~ page.extra.cover.image, width = 600, op = 'fit_width') %}
{% set resized_image_metadata = get_image_metadata(path = resized_image) %}
<meta property="og:image:width" content="600" />
<meta property="og:image:height content="{{ resized_image_metadata.height }}" />

Does anybody know how to get the image metadata of an image that has been resized?

Thanks!

1 Like

That’s a very good question… What’s happening with that snippet?

I get this error message when I run zola serve:

Reason: Failed to render 'page.html'
Reason: `get_image_metadata`: Cannot find path: http://127.0.0.1:1111/processed_images/4531f16bdedc7bba00.jpg