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();
   $url = $file->createFileUrl();
   OR
   $path = 'public://images/image.jpg';
   $url = \Drupal\image\Entity\ImageStyle::load('medium')->buildUrl($path);
Get default file path (get original file path)
$url = file_create_url($path);
OR
$url = $file->createFileUrl();
Comments2
small issue in last line
I think it should be
$url = \Drupal\image\Entity\ImageStyle::load('medium')->buildUrl($path);
Yes, Thank you.
Yes, Thank you.