0

I am trying to output this image :

enter image description here

However, nothing gets printed out. My code is

print render($media_item->field_media_photo['und'][0]

Why doesn't it work?

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Evaldas Raisutis
  • 1,628
  • 4
  • 18
  • 32

2 Answers2

2

Use image_style_url instead.

$image_uri = $media_item->field_media_photo['und'][0]['uri'];
$image_stylePath = image_style_url("large", $image_uri);
print theme("image", array(
    'path' => $image_stylePath
));
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
  • 2
    Even better, use [`theme_image_style()`](https://api.drupal.org/api/drupal/modules!image!image.module/function/theme_image_style/7) – Clive Jan 21 '14 at 16:18
1

It wont work that way. Best way is to use theme function.

$image = theme('image', $vars);
$path = $media_item->field_media_photo['und'][0]['uri'];

$vars =  array(
  'path' => $path , 
  'alt' => 'alt',
  'attributes' => array('class' => 'example'),
  );

here only the path is mandatory. You can print the variable $image in a .tpl file and the image will appear.

bodi87
  • 501
  • 1
  • 6
  • 18