How can I get the width or height of an image field image into a twig template? I'm using PhpStorm/xdebug/MAMP to look at the variable I want to access:



I have tried using the following to get at the data:

{% set image_width = content.field_image.0['#item'].values.width %}


and

{% set image_width = content.field_image.0['#item'].values.width.value %}


Neither of these lines produce any data.

Any help is greatly appreciated!
You can't access the array values because it is protected. But you don't need to, because you can get the properties from a field item directly:

{% set image_width = content.field_image.0['#item'].width %}


BTW the content variable is a render array with no fixed structure. The presence and position of #item changes dependent on the field formatter and other core, contrib or custom code.

So it's better to use the entity object, for example the paragraph entity in a paragraph template:

{% set image_width = paragraph.field_image.0.width %}