How do you wrap an image with a link?
This way should be bulletproof:

use Drupal\Core\Link;
use Drupal\Core\Render\Markup;

$url = $node-&gt;get('field_url')-&gt;getValue();
$imageUri = $node-&gt;get('field_image')-&gt;entity-&gt;getFileUri();
$image = [
  '#theme' =&gt; 'image_style',
  '#style_name' =&gt; 'medium',
  '#uri' =&gt; $imageUri,
  '#width' =&gt; 200,
  '#height' =&gt; 100
];
$rendered = render($image)
$linkMarkup = Markup::create($rendered);
$link = Link::fromTextAndUrl($linkMarkup, $url);
$link = $link-&gt;toRenderable();
render($link)