将图像样式应用于从Drupal网站上的单独节点渲染的图像


Apply image styling to images rendered from separate nodes on Drupal site?

我的网站上有一个页面,它使用entityFieldQuery方法过滤来自单独页面的内容。问题是,我过滤到新页面上的图像需要应用不同的图像样式,以便加载到较小的图像中。我在网站上设置了图片映射,但我只通过Drupal工作台在图像字段中应用了它,在那里你可以从下拉列表中选择图像样式。

下面的代码是我的entityfieldquery和条件语句,用于创建从另一个页面过滤到当前页面的内容。有没有什么方法可以修改这个代码,将不同的图像样式应用于正在生成的图像?

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
    ->propertyCondition('status', NODE_PUBLISHED)
    ->propertyCondition('type', 'Blog')
    ->propertyCondition('created', array($old_date, $current_date),'BETWEEN')
    ->propertyOrderBy('created', 'DESC')
    ->fieldCondition('field_blog_categories', 'tid', $term_id)
    ->fieldCondition('field_blog_categories', 'tid', array('55', '26'))
    ->range(0, 9);
    $result = $query->execute();
    }
    if(isset($result['node'])) {
        $blog_items_nids = array_keys($result['node']);
        $blog_items = entity_load('node', $blog_items_nids);    
        if (count($blog_items)>2){
        $data = array();
        foreach ($blog_items as $blg) {
            $field_blog_header_image = field_view_field('node', $blg, 'field_blog_header_image', 'picture');
            $temp_blog_cat = field_view_field('node', $blg, 'field_blog_categories');                       
            $data[$temp_blog_cat['#items'][0]['tid']][] = array(
                'blog' => $temp_blog_cat["#object"]->title,
                'img'  => isset($field_blog_header_image) ? render($field_blog_header_image) : '',
                'link' => $temp_blog_cat['#object']->path['alias'],
            );
        }
    ?>

是的,您可以使用函数image_style_url():

https://api.drupal.org/api/drupal/modules!形象image.module/function/image_style_url/7

该函数将以传递给它的任何样式为您提供图像的路径,只要您可以获取图像URI并将其作为参数传递给它。

因此,检查您从视图中获得的值,找到如何获得图像URI并将其称为:

$image_path = image_style_url('style_name', $uri);