Uri to image style url [drupal 8]

A much needed functionality is how you get the url of an image style form the uri (f.e. in a node object). This snippets helps you accomplish this.

use Drupal\image\Entity\ImageStyle;

$url = ImageStyle::load('large')->buildUrl($node->field_image->entity->getFileUri());
// You now have the url of your image

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!