Drupal 7 Get image field path

Davide De Maestri picture Davide De Maestri · Oct 7, 2011 · Viewed 49k times · Source

I would like to get the image path of a field. I'm in a node and I need the Url of image in order to put it as a background-image in inline css. I can't find the solution. Can you help me?

Answer

MunkyOnline picture MunkyOnline · Jul 6, 2012

To get just the path of an image from it's URI:

file_create_url($node->field_image['und'][0]['uri']);

More information on file_create_url() can be found here: http://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7

To get the path of an image created using an image style from it's URI use:

image_style_url($style, $node->field_image['und'][0]['uri']);

More information on image_style_url() can be found here: http://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7