When using the image.imagemagick.inc and the imagecache module to create resized images (not *scaled* images), the images still come out with relative sizing. image.imagemagick.inc should use the resize function instead of the scale function.

Steps to replicate:

1) Install image.imagemagick.inc and set your Image Toolkit

2) Create a new imagecache namespace

3) Choose resize (not scale) and set width and height to 100px x 100px

4) Upload a non-square image using node/add/image

5) View the imagecache-generated image ( /files/imagecache/namespace/filename.jpg)

Patch attached to:

a) Use the resize function and not scale in _resize()

b) Allow the use of an exclamation point in the command filter

CommentFileSizeAuthor
#7 imagemagick.resize_0.patch1.12 KBdrewish
imagemagick.resize.patch949 bytessamo

Comments

drewish’s picture

what does the ! do?

samo’s picture

It forces an exact resize.

By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.

http://www.imagemagick.org/script/command-line-options.php

drewish’s picture

samo, can you take a look at http://drupal.org/node/29528 and integrate anything of use into your patch and then mark that as a duplicate of this issue?

drewish’s picture

samo, can you do the same for http://drupal.org/node/20517 ? steal any good ideas and close the issue?

drewish’s picture

humm comparing the docs for -resize and
-scale makes me think that -scale is probably correct. i'll have to walk through your steps and check that ! is worthwhile.

samo’s picture

drewish,

The two issues you pointed to both seem concerned with image quality. My concern is simply that I don't believe the imagemagick resize function is doing the right thing. I believe your resize function is scaling images (maintaining the original aspect ratio) instead of truly resizing the image to the exact dimensions as requested.

If a calling module wants to resize an image while maintaining the original aspect ratio, the module should use image_scale. Image scale will then interpret the width and height parameters passed to it, adjust the width and height to match the aspect ratio, and the call the toolkit's image_resize function with the new width/height params.

But if a module (e.g., imagecache) wants to resize an image to exact dimensions, the module should call image_resize and the requested width and height params will be passed directly to the implementing toolkit's image_resize function.

I believe your imagemagick image_resize function is not handling the second case correctly. By using the -scale function, you are forcing the maintenance of the original aspect ratio.

To sum: image.inc handles aspect ratios; image.imagemagick.inc should just resize the image to the exact dimensions passed to it. Currently, this is not true.

drewish’s picture

StatusFileSize
new1.12 KB

okay i get your point about not honoring the sizing. but i think my point about -scale being the correct choice still stands. here's a patch to use the ! to specify the size and allow it through the filter.

samo’s picture

your patch works as advertised.

staying with -scale is fine as the only point of the patch was to fix the bug. but -scale and -resize are essentially the same, except for differing algorithms and less control with scale. for one, the use of a -filter after -scale in your current function seems pointless:

See -resize for details about the geometry specification. -scale uses a simpler, faster algorithm, and it ignores the -filter selection if the -filter option is present. Offsets, if present in the geometry string, are ignored, and the -gravity option has no effect.

samo’s picture

Status: Needs review » Reviewed & tested by the community
drewish’s picture

Status: Reviewed & tested by the community » Fixed

cool, this has been committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)
TigerNuve’s picture

Hello, I am not a developer, but want my editors to be able to upload an image to a Drupal site customised gallery and for the image to resize automatically to the standard format for that gallery each time. Is this possible using image.imagemagick.inc? Thanks for any replies and help from dumbo here.