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);

Get default file path (get original file path)

$url = file_create_url($path);

Get internal path (Server side)

$image_path = drupal_realpath($path);

Get an image style path

Example : Image style : 'medium'
$fid = 1; // The image file ID.
$file = \Drupal\file\Entity\File::load($fid);
$path = $file->getFileUri();
$image_url = \Drupal\image\Entity\ImageStyle::load($style_name)->buildUrl($path);

Comments

moncler coat
kd 10
pandora
adidas originals ultra boost
skechers outlet
north face jacket
louboutin shoes
nmd
air max 270
nike air max
nike air max 95 mens
pandora bracelet
birkenstock shoes
nike air max 95
kate spade bags
swarovski rings
mcm backpack
bvlgari
nike air max
ralph lauren
kyrie irving shoes
balenciaga
Pandora
cartier bracelet
jordan
jordan retro 11
asics womens running shoes
yeezy
air max 90
pandora jewelry
nike air vapormax flyknit
oakley glasses
yeezy boost 350 v2
mbt mens shoes
curry 4 shoes
burberry outlet
yeezy
supreme jacket
new balance
chrome hearts jewelry
moncler coat
moncler
uggs for women
adidas superstar shoes
nike air max 270 men
pandora,pandora charms
air max 90
swarovski bracelet
pandora bracelet
adidas nmd
pandora bracelet
pandora charm
true religion sale
ralph lauren shirts
nike air max 90
red bottoms
moncler jacket mens
nike air max 95
prada bags
kd 9
air max 97 gold
pandora rings
adidas nmd
michael kors handbags
curry shoes
pandora charms
nike air max 95
ray ban prescription sunglasses
ray ban eyeglasses
longchamp backpack
ultra boost
ray ban glasses
Yeezy Boost 350 V2
lebron 14
barbour wax jacket
kevin durant shoes
ed hardy clothing
kate spade handbags
oakley
salomon skis
air jordan
mulberry
michael kors handbags
fitflop uk
pandora jewelry
salomon shoes
chrome hearts pendant
jordan 11 space jam
fitflop sale
lacoste polo shirts
salvatore ferragamo
nike vapor max
goyard backpack
adidas shoes
ecco sandals
air max 97 mens
coach purses
burberry purses
skechers
Salomon Speedcross 3
ugg boots
jordan shoes
lebron shoes
skechers
kyrie irving shoes
pandora jewelry official site
goyard wallet
huarache shoes
red bottom shoes
salvatore ferragamo
red valentino
north face outlet
Hermes Birkin Bags
ralph lauren
huarache shoes
james harden shoes
supreme shirt
uggs on sale
air max 95
mont blanc
polo ralph lauren
yeezy boost
under armour jackets
balenciaga bags
kate spade bags
longchamp
ugg
nike vapormax
air max 90
salomon speedcross 3
yeezy shoes
asics shoes
fitflop
jimmy choo shoes
ray ban
nike air max
mulberry sale
barbour wax jacket
moncler sale
prada handbags
burberry
hermes belt
yeezy boost 350
nike shoes
jordan shoes
louboutin shoes
yeezy boost 350
birkenstock sandals
chrome hearts t shirt
fitflops clearance
moncler
mcm backpack
celine,celine bag
coach purses
true religion jeans for women
nike vapormax
puma fenty
yeezy boost 350 v2

Add new comment