Drupal 8 - Get the image width / height / alt / etc.. in a twig or preprocess file
<p>I'm trying to get the width and height of an image in a preprocess file.</p>

<p>I managed to generate the image with a style defined in the media/styles in the admin but I'm not able to render the width and/or height of the generated image (some will say I should just hardcode it in the twig file but I'm actually interested in learning how to get elements I'll need later :))</p>

<p>Here is what I'm using to get the image of a certain content type:
Let's assume my field's machine name is "field_image" and my content type is "article";</p>

<pre><code>if (!empty($node-&gt;field_image-&gt;entity-&gt;getFileUri())) {
  $style = ImageStyle::load('medium');
  $image = $node-&gt;field_image-&gt;entity;
  $variables['image'] = [
    'src' =&gt; $style-&gt;buildUrl($image-&gt;getFileUri())
  ];
}
</code></pre>

<p>After that, all I need to do in node--article.html.twig is:</p>

<pre><code>&lt;img src="{{ image.src }}" /&gt;
</code></pre>

<p>But I also want to get the width and height attributes. How can I do that?</p>