I'd do it another way. In your node preprocess function :
use Drupal\image\Entity\ImageStyle; // Don't forget this use.
function THEMENAME_preprocess_node__NODETYPE(&$variables){
$node = $variables['node'];
if(isset($node->get('field_image')->entity)){
$image_style = 'large'; // Or whatever your image style's machine name is.
$style = ImageStyle::load($style);
$variables['image'] = $style->buildUrl($node->get('field_image')->entity->getFileUri()); // Generates file url.
}
}
Then, in your template (node--NODETYPE.html.twig), just render the image that way :
{% if image %}
<img src="{{ image }}" />
{% endif %}
Although, if you ever have to render a big amount of images, I'd advise you to load the styles in an array before you loop on each images. I'm saying that because I've ran into serious load time problems because I had to load over 300 images and for each image, I was loading the style individually instead of loading them all before, here's an example, same base as above :
use Drupal\image\Entity\ImageStyle; // Don't forget this use.
function THEMENAME_preprocess_node__NODETYPE(&$variables){
$node = $variables['node'];
if(isset(node->get('field_images')[0]->entity)){ // Notice how, this time, I check if the FIRST image is set (if it's true, then u'll allow the loop for at least 1 element)
$images_styles = [
'large' => ImageStyle::load('large'),
'thumbnail' => ImageStyle::load('thumbnail')
];
$count = 0;
foreach($node->get('field_images') as $image){
$variables['images'][$count]['large'] = $images_styles['large']->buildUrl($image->getFileUri());
$variables['images'][$count]['thumbnail'] = $images_styles['thumbnail']->buildUrl($image->getFileUri());
$count++;
}
}
}
Then again, in your template (node--NODETYPE.html.twig), just render the images that way :
{% if images %}
<ul>
{% for image in images %}
<li>
<img src="{{ image.large }}" /> // Large image url.
<img src="{{ image.thumbnail }}" /> // Thumbnail image url.
</li>
{% endfor %}
</ul>
{% endif %}
I haven't really tested it and I'm getting all this out of my head so it might contain errors, feel free to warn me so I'll correct this :-).