In Chapter 4, Theming, we talked about theme hooks and how we use them in render arrays to build output. And we also saw a few examples of theme hooks that come with Drupal core and which can be used for common things (such as links or tables). But images are also something we’ll often end up rendering and there are two ways we can do so (both using theme hooks defined by Drupal core).
First, we can use the image theme hook to simply render an original image. And it’s pretty simple to use it:
return [ '#theme' => 'image', '#uri' => 'public://image.jpg', ];
And this will render the image as is. We can also pass some more options like the alt, title, width or height which will be applied to the image tag as attributes, as well ...