是否有即时的drupal图像缩放器?

时间:2011-04-21 16:53:46

标签: php drupal

Drupal或Drupal模块中是否有图像缩放器可以让您执行以下操作:

theme_image_resize($source, $heightx$width, $options);

3 个答案:

答案 0 :(得分:6)

Drupal 7带有图像样式,可让您创建包含缩放,裁剪和许多其他图像处理操作的预设。您可以使用theme_image_style()以编程方式调整任何图片大小:

$options = array(
  'style_name' => 'small', // Machine name of style defined in Admin UI or image_style_save()
  'path' => 'public://myimage.png',
  'alt' => t('resized image'),
  'title' => t('resized image'),
  'attributes' => array(
    'class' => array('awesome', 'inset', 'resized'),
    'rel' => 'lightbox',
  ),
);
$image_html = theme('image_style', $options);

Drupal 6相当于使用ImageCache,它具有类似的API和工作流程。

答案 1 :(得分:3)

顾名思义, ImageCache 会缓存已调整大小的图片,因此下次不会再对其进行动态调整。

ImageCache被移植并包含在Drupal 7的核心中,因此theme_image_style()相当于它。

这些“高效包装”可能就是你要找的东西。但如果你只需要调整大小函数,那么看看Drupal核心中的image.inc,它包含[image_resize()2

这个Drupal 6函数将调用您在Drupal站点中启用的Image Toolkit(G2或Imagemagick)。

对于Drupal 6,ImageAPI具有非常相似的功能但处理图像的效率更高,并且已经包含在Drupal 7的核心中,所以要注意image_resize()的参数差异在Drupal 7中。

答案 2 :(得分:2)

有模块。它被称为http://drupal.org/project/image_resize_filter。您需要制作新的文本过滤器格式,仅添加图像调整大小过滤器,注意过滤器机器名称。然后在代码中使用check_markup()将过滤器应用于图片代码的html字符串。过滤器将查找宽度和/或高度标签以调整图像大小并将调整大小保存在文件系统中以备将来使用。