开发者

Is there a on-the-fly drupal image resizer?

Is there an image开发者_如何转开发 resizer in Drupal or in a Drupal module that would let you do something like:

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


Drupal 7 comes with image styles, which lets you create presets that include scaling, cropping, and a host of other image manipulation actions. You can resize any image programmatically using 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);

The Drupal 6 equivalent is to use the ImageCache, which has a similar API and workflow.


As the name said, ImageCache will cache the resized image, so it's not anymore resized on-the-fly in the next times.

ImageCache was ported and included in Drupal 7's core, so theme_image_style() is the equivalent of it.

These "efficient wrappers" are probably what you are looking for. But if you want only the resize function, then have a look to image.inc in Drupal core, which contains [image_resize()2.

This Drupal 6 function will call to the Image Toolkit you have enabled (G2 or Imagemagick) in your Drupal site.

In case of Drupal 6, ImageAPI has really similar functions but more efficient way of handling images, and has been included in Drupal 7's core, so pay attention to the differences in the arguments of image_resize() in Drupal 7.


There is module for that. It is called http://drupal.org/project/image_resize_filter. You need to make new text filter format, add only Image resize filter, note filter machine name. Then in code apply filter to html string of your image tag using check_markup(). Filter wil look for width and/or height tag to resize image and save resized in your file system for future use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜