Jan 25, 2021 in Drupal 8

This technique is used quite a lot to get an image styled url of an image in your twig file.

use Drupal\image\Entity\ImageStyle; // on top

function THEMENAME_preprocess_node(&$vars) { 
   if(($node->getType() == 'partner_logo') && ($variables['view_mode'] == 'teaser')) {
    $id = $node->field_logo->entity->getFileUri();
    $url = ImageStyle::load('partner')->buildUrl($id);
    $variables['image_url'] = $url;
  }
}

Then, in your partner-logo--teaser.html.twig:

<div style="background-image:url('{{ image_url }}'); background-size: cover"></div>