logo

额外区块类型 (EBT) - 全新的布局构建器体验❗

额外区块类型 (EBT) - 样式化、可定制的区块类型:幻灯片、标签页、卡片、手风琴等更多类型。内置背景、DOM Box、JavaScript 插件的设置。立即体验布局构建的未来。

演示 EBT 模块 下载 EBT 模块

❗额外段落类型 (EPT) - 全新的 Paragraphs 体验

额外段落类型 (EPT) - 类似的基于 Paragraph 的模块集合。

演示 EPT 模块 滚动

滚动

以编程方式使用图像预设(programmatically use imagecache)

11/10/2025, by Ivan

与 Drupal 6 相比,Drupal 7 中的 ImageCache API(图像样式)有所变化。在 Drupal 6 中,我们可以通过以下方式以编程方式使用图像预设(preset):

<?php print theme('imagecache', 'my_preset', $file_path, $alt, $title, $attributes); ?>

例如:

theme('imagecache', '300x300crop', $first_photo["filepath"], $node->title, $node->title, array('itemprop' => 'image'));

而在 Drupal 7 中,代码写法略有不同:

print theme_image_style(array(
  'style_name' => 'home_category_image',
  'path' => $result['node']->field_image['und'][0]['uri'],
  'alt' => $title,
  'width' => '',
  'height' => '',
  'attributes' => array('class' => 'search-result-img'),
));

现在我们使用 theme_image_style() 函数,并向其传递一个参数数组:

  • style_name — 预设名称。
  • path — 图像路径,包括上传方式和文件地址,例如:public://product/421-a1 amt.jpg,其中 public 表示公共文件系统。
  • alt — 图像的替代文本(alt 属性)。
  • widthheight — 宽度和高度。可以不指定,但这可能会触发 notice 提示。
  • attributes — 其他属性,通过数组传递。