Imagesize (bits and bytes) after processing

I have a little “do it once and then forget” project where I create (currently only) page-bundle based image tags with “all the formats modern browsers love”, as in webp and such. Now currently it outputs webp preferred and if the browser supports webp then it displays this image. There are cases though, where the webp version is larger than the jpeg or png version of an image. Let’s not discuss the underlying issues here, let’s concentrate on the other problem:

How can I know the file size of a processed image in my partial or shortcode? After resizing, filtering, type-assigning. Is there a way to get the amount of bytes that this image requires and decide some form of order based on all image versions and their file sizes?

I am pretty sure I saw this happening somewhere, but I can’t find it in the documentation.

Would len work? Image processing: get size in MB

The knowledge of img.Content would have helped already. Let me check where the documentation hides this parameter :slight_smile:

I would be very curious to knwo if you found an answer. We’re playing a lot with Hugo transformations on GitHub - theNewDynamic/hugo-module-tnd-media: A catch-all solution for handling media in your Hugo project and the more we know about the final transformed asset the better.