Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 936 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drupal 7 Get image field path

#1
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?
Reply

#2
I sometime use this:

$node = node_load($nid);
$img_url = $node->field_userimage['und'][0]['uri'];

<img src="<?php print image_style_url($style, $img_url) ?>" />
Reply

#3
To get just the path of an image from it's URI:
<pre>file_create_url($node->field_image['und'][0]['uri']);</pre>

More information on file_create_url() can be found here:

[To see links please register here]


To get the path of an image created using an image style from it's URI use:
<pre>image_style_url($style, $node->field_image['und'][0]['uri']);</pre>

More information on image_style_url() can be found here:

[To see links please register here]

Reply

#4
I am afraid, none of the solutions above are correct. They don't follow Drupal standards.

// field_video_image is the name of the image field

// using field_get_items() you can get the field values (respecting multilingual setup)
$field_video_image = field_get_items('node', $node, 'field_video_image');

// after you have the values, you can get the image URL (you can use foreach here)
$image_url = file_create_url($field_video_image[0]['uri']);

More details here:

[To see links please register here]

Reply

#5
You also can use the [Image URL Formatter][1] module. It allows to change the field format in order to get only the URL:


![Drupal field settings][2]


Bonus: it works with Views as well:


![enter image description here][3]


[1]:

[To see links please register here]

[2]:

[3]:
Reply

#6
to get image style url:

$field = field_get_items('node', $node, 'field_image');
$image_url = image_style_url('landingpage_slider', $field[0]['uri']);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through