我正在Drupal7中创建一个模块。如果我想将UNIX时间戳格式化为日期,我可以使用format_date函数,如下所示:
$date = format_date($node->created, 'custom', 'j F Y');有没有我可以引用的格式化图像的函数?假设我的数据库查询返回
picture-4-136576449.png从一个表中,我想将它转换为:
<img src="/images/picture-4-136576449.png />有没有一个函数可以做到这一点?谢谢。
发布于 2013-02-08 03:33:16
如果您尝试将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()函数doc page中看到其他变量。
https://stackoverflow.com/questions/14759103
复制相似问题