Forked from slivorezka/get_image_path_with_image_style.php
Created
September 14, 2019 16:27
-
-
Save manniresystems/eea27ab9c2319e3c5517e19dcddbb313 to your computer and use it in GitHub Desktop.
Drupal 8: Get Image URL / URI with Image Style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\file\Entity\File; | |
use Drupal\image\Entity\ImageStyle; | |
// File ID. | |
$fid = 123; | |
// Load file. | |
$file = File::load($fid); | |
// Get origin image URI. | |
$image_uri = $file->getFileUri(); | |
// Load image style "thumbnail". | |
$style = ImageStyle::load('thumbnail'); | |
// Get URI. | |
$uri = $style->buildUri($image_uri); | |
// Get URL. | |
$url = $style->buildUrl($image_uri); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment