Add image styles with images I am trying to print an image using an image style that I've created in my drupal 8 theme.

I'm implementing a field template for the field collection. I have an image in my field collection, So i need a way to get the URL for a different image style of the same image.

Any effort will be appreciated.
mythemename.theme

use Drupal\image\Entity\ImageStyle;
use Drupal\file\Entity\File;


function mythemename_preprocess_page(&amp;$variables) { 
// change _page to _node or _html depending on the template you are targetting.

  if (isset($variables['node'])) {
    $node = $variables['node'];
    // now you can use $node-&gt;field_something

    // Since I have yet to use field collection in D8, I'll let you figure this part out.
    // So all you gotta do is get the fid from your image field.

    // Once you get the FID 
    $file = File::load($fid);
    $uri = $file-&gt;getFileUri();
    $url_large = ImageStyle::load('large')-&gt;buildUrl($uri);
    $url_medium = ImageStyle::load('medium')-&gt;buildUrl($uri);
    $variables['large_image_style_url'] = url_large;
    $variables['medium_image_style_url'] = url_medium;
  }
}


Then in twig you can do {{ large_image_style_url }} and {{ medium_image_style_url }}

I had to do it like this, since I needed to print the image in page.html.twig. If you need yours in node.html.twig you could try the answers to How to use an image style in a Drupal 8 twig template?