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
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | imagemagick.resize_0.patch | 1.12 KB | drewish |
| imagemagick.resize.patch | 949 bytes | samo |
Comments
Comment #1
drewish commentedwhat does the ! do?
Comment #2
samo commentedIt forces an exact resize.
http://www.imagemagick.org/script/command-line-options.php
Comment #3
drewish commentedsamo, 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?
Comment #4
drewish commentedsamo, can you do the same for http://drupal.org/node/20517 ? steal any good ideas and close the issue?
Comment #5
drewish commentedhumm 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.
Comment #6
samo commenteddrewish,
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.
Comment #7
drewish commentedokay 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.
Comment #8
samo commentedyour 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:
Comment #9
samo commentedComment #10
drewish commentedcool, this has been committed.
Comment #11
(not verified) commentedComment #12
TigerNuve commentedHello, 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.