Images are not resized when using both max and min.

Max: 320x240
Min: 320x240
Image: 800x600
Error:

The selected file x.jpg could not be uploaded. The image must be exactly 320x200 pixels.

This should be allowed. I want to make sure smaller images are not scaled up, resulting in poor quality.

Images are resized when using just max.

Max: 320x240
Min: 0
Image: 800x600
Success
Resized to 320x240

Comments

quicksketch’s picture

This was intentional because it EXTREMELY unlikely that a user would just so happen upload a file that is the exact right ratio that the image would be scaled down to fit an exact set of pixels. Therefor if both max and min are set to the same value, ImageField intentionally requires an image exactly that size.

hawleyal’s picture

At the very least, it is unexpected behavior. There is no indication that if both max & min are set, that they should enforce an exact size.

Either of 2 possible scenarios:
1. Max and min could behave as stated, and there could be a separate setting for exactness.
2. Max and min statements change to include the exactness clause, and it is not possible to achieve what I am doing.

It is even more unlikely that people would want to upload an exact dimensions of an image.

It seems to me if resizing is the goal, a developer would always set the max and min to the same dimensions. You want to always ensure resizing is done from a larger image than required. That is, only scaling down, no scaling up.

E.g.:
max: 200x200, min: 200x200
upload: 300x300 allowed, scaled to 200x200
upload: 300x200 allowed, scaled/cropped down to 200x200
upload: 200x300 allowed, scaled/cropped down to 200x200
upload: 200x200 allowed, unchanged
upload: 100x100 not allowed

No?

quicksketch’s picture

Category: bug » feature

There is some indication. If max and min are set to the same size, the help text displayed to the user states, "The image must be exactly 100x100." It's definitely intentional and is considered to be "expected" considering it was actually requested multiple times before this was implemented.

#370831: Trying to enforce a set image resolution using minimum and maximum resolution.
#119585: Force an exact dimension with minimum and maximum image size

However at one time there was a request to add checkboxes for resizing (I think it was actually #370831). If added this would fix the problem you're experiencing.

[x] Scale oversized images to fit within the Maximum Resolution
[ ] Scale undersized images to fit within the Minimum Resolution
joachim’s picture

Category: feature » bug

> There is some indication. If max and min are set to the same size, the help text displayed to the user states

Yes, there's an indication, but it's silly.

If I set only a max sixe, it scales. If I add a min size, oversize images should still scale down. Bug in admin UI expectation.

quicksketch’s picture

Category: bug » feature

If I add a min size, oversize images should still scale down.

Images will still be scaled down, just as long as max and min aren't identical (or if scaling down from maximum on one dimension would cause the image to fall below the minimum on the other dimension). I would believe that if I set max and min to be identical, only images of that exact size would be allowed. It's unlikely that your users would just so happen to upload an image at the exact right ratio anyway. If they've got the ratio perfect, they probably can scale to the right size also.

joachim’s picture

> I would believe that if I set max and min to be identical, only images of that exact size would be allowed. It's unlikely that your users would just so happen to upload an image at the exact right ratio anyway. If they've got the ratio perfect, they probably can scale to the right size also.

I really wouldn't!

What I expect from setting the sizes the same in admin is that I want large images shrunk down to this size, and also I want nothing smaller than this size because scaling up would look ugly. This seems a fairly reasonable set-up to want if, say, you wanted users to put thumbnails on posts.

quicksketch’s picture

I want large images shrunk down to this size, and also I want nothing smaller than this size because scaling up would look ugly.

I'm saying as long as min and max aren't set to the exact same size, this is exactly what happens. If you set the image size to a min of 640x480 and a max of 640x480 what are the chances that an average user will upload an image that will match that ratio, when most cameras, screenshots, and video clips are not that ratio? The ONLY time exact size is enforced is when min and max are identical. If images aren't the exact right ratio, it would be impossible for ImageField to accept the image without cropping. If you want cropping, you're much better off accepting the image at any ratio and crop it with a module like ImageCache or ImageField Crop.

leo pitt’s picture

Hi,

I'm also a bit confused by this behaviour.

I want the uploaded images to be automatically scaled and cropped down to fit 571x294 pixels, and anything smaller than that to be rejected.

Is there anyway enforcing this using the ImageField configuration settings?

I tried setting maximum resolution to 572x295 and minimum resolution to 570x293, but it did not work.

Thanks

quicksketch’s picture

ImageField will never crop photos on upload. If you want to do cropping, it should be handled with ImageCache.

coderintherye’s picture

I just want to add +1 to finding this confusing. I did not expect when setting a min and max to have the behavior of expecting exact dimensions. Could you point to the original issues that called for this? The reason I ask, is I could see how you the maintainer, may expect this behavior, but as an administrator who had not previously tried setting these fields, I did not expect this outcome at all.

quicksketch’s picture

See #3 for my summary. At this point it's practically too late to change anyway, since the current interface we have in ImageField is the same thing that's in Drupal 7 core, and not going to be changed at this point.

coderintherye’s picture

Thanks, however I was referring to your statemenet:

However at one time there was a request to add checkboxes for resizing (I think it was actually #370831)

I didn't see such a request in #370831.

That said, if you are not going to do this suggestion, could you please mark this as won't fix and close it.

quicksketch’s picture

Status: Active » Closed (won't fix)