Drupal7函数用于格式化图像URL



我正在Drupal7中创建一个模块。如果我想将UNIX时间戳格式化为日期,我可以使用format_date函数,如下所示:

$date = format_date($node->created, 'custom', 'j F Y');

是否还有一个我可以参考的函数来格式化图像?假设我的数据库查询返回

picture-4-136576449.png

从一个表,我想把它转换成:

<img src="/images/picture-4-136576449.png />

有函数可以做吗?谢谢

如果您试图将URI转换为URL,则说明您做得不对。

$uri = 'public://images/my-photo.png';
$url = file_create_url($uri);
// $url should be publicly accessible URL now. 

如果您知道相对于Drupal根的图像路径,请使用

$url = url('path/to/image.png', array('alias' => FALSE));

可以使用theme('image', $variables)为图像设置主题。

例如:

<?php 
print theme('image', array('path' => 'path/to/image.png', 
                           'title' => t('Some title'), //optional
                           'alt' => t('Some alt text'), //optional
                      ));

您可以在theme_image()函数文档页面上看到其他变量。

最新更新