Is it possible to get a transformed image's file size (bytes, not dimensions)? I'm using a transformed image in a context where there's a maximum file size. Is there a way to determine the transformed image's file size in the templates? .size can't run on the url string
I don't think it's possible to get the file size of an image after it's been transformed with Craft's out-of-the-box image transforms.

It looks like the .size property only works on the original asset file.

Even if you did something like this...

{% set image = entry.myAssetField.one() %}

{% set thumb = {
    mode: 'crop',
    width: 100,
    height: 100,
    quality: 75,
    position: 'top-center'
} %}

{% if image %}

  {% do image.setTransform(thumb) %}

  {{ image.width }} x {{ image.height }} = {{ image.size }} bytes

{% endif %}


.height and .width properties will show the transformed dimensions (100 x 100), but .size outputs the original file size, not the transformed size.

I'm guessing this might be a problem for Craft because the transformed image may not have been generated before the template is rendered.

Update

The Imager plugin has a getSize method that should work. Imager transforms are created before the template is rendered.

getSize($unit='b', $precision='2') [float]

{{ image.getSize() }} B 
{{ image.getSize('k') }} KB 
{{ image.getSize('m', 10) }} MB 
{{ image.getSize('g', 10) }} GB