Get a Image file path (src) on Drupal 8 | Drupal 8

Get a Image file path (src) on Drupal 8

Submitted by editor on Wed, 12/16/2015 - 23:44
Question

How to display an image file (or get the src to render) in Drupal 8 ?

Get the image file src (url)   
    $fid = 1;//The file ID   
    $file = \Drupal\file\Entity\File::load($fid);
    $path = $file->getFileUri();
    OR
    $path = 'public://images/image.jpg';
    $url = \Drupal\image\Entity\ImageStyle::load('medium')->buildUrl($path);

Comments

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.