Drupal 7获取图像字段路径 [英] Drupal 7 Get image field path
问题描述
我想获取一个字段的图像路径。我在一个节点,我需要图像的Url,以便将其作为背景图像inline css。
我找不到解决方案。你可以帮助我吗?
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?
推荐答案
只需从URI中获取图像的路径:
To get just the path of an image from it's URI:
file_create_url($node->field_image['und'][0]['uri']);
有关file_create_url()的更多信息,请参见: http: //api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7
More information on file_create_url() can be found here: http://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7
获取创建图像的路径使用它的URI使用图像风格:
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']);
有关image_style_url()的更多信息,请参见: http://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7
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
这篇关于Drupal 7获取图像字段路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!