Drupal 7 获取图像字段路径 [英] Drupal 7 Get image field path
问题描述
我想获取字段的图像路径.我在一个节点中,我需要图像的 URL,以便将其作为内联 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屋!