4

As you may know, in Drupal 7 you can set max and min dimensions for an image field, when you upload a small image, Drupal returns an error, but when you upload a bigger file it resize the image automatically instead of return the error "Your image is too big...".

I was looking for the reason of that autoscale configuration but looks like it will never be fixed. I need to override it because some of my users still uploading pictures with other dimentions, even with a different aspect ratio.

I found the condition in includes/file.inc line 1809 ... it tries to scale the image if it's bigger. I know that i can comment that condition and it will work, but is not a good idea, so: Does anyone know how to override that condition using a custom module, hooks or something?

4
  • Might be misunderstanding, but if you don't need the max resolution setting why not just remove it?
    – Clive
    May 13, 2015 at 17:04
  • I need users upload images of 500x500 (exact size), but when the user uploads an image of (example) 800x900 the image is scaled to 500x500 (keeping aspect ratio)... in this case i need that Drupal return "The image is too big" instead of scale it by it self
    – xstean
    May 13, 2015 at 18:06
  • I know this is an old post, but I have the very same problem/desire. I want to force users to upload an image of an exact width. I don't want any kind of auto-resizing or scaling. I don't want to use an image style. Feb 22, 2019 at 18:36
  • @MarshallMorrise has I said, you can change the core
    – xstean
    Mar 12, 2019 at 16:01

2 Answers 2

1

You don't want to return the message "your image is too big" as people nowadays are uploading directly from their mobile phones and do not have (or know) a way of resizing/cropping themselves before uploading.

So you should try it via another way: do not impose restrictions on the original image, but use an image style to display the uploaded images and add some smart/user/custom crop effect to that image style. There are a number of modules that let users/editors custom crop images, e.g:

Also see Comparison of image cropping and resizing modules.

1
  • I couldn't find the solution for what i needed, i think it's a little detail that could be fixed, at least a checkbox that let you force an exact image size. Btw ImageField Crop worked for me, thank you!
    – xstean
    Sep 9, 2015 at 14:20
0

You need to go to manage fields and click edit on your image field.

you should see Maximum image resolution and Minimum image resolution. Try setting both of these fields to 500x500

Note: if you are using the default Drupal user pictures in admin/config/people/accounts you would have to turn them off, since you can't give them a max/min resolution. Then just add an image field in admin/config/people/accounts/fields and use that as user pictures.

6
  • yet it allows people to upload and change their pic?
    – No Sssweat
    May 15, 2015 at 18:12
  • I'm talking about image fields in content types .. and that's not the problem. I already set min and max resolutions... if you go to edit field page.. right after "Max resolution" settings you will see this: "The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of..." That's what i'm talking about
    – xstean
    May 15, 2015 at 18:17
  • oh dang, I didn't read that part. I thought Drupal would reject it just like min resolution.
    – No Sssweat
    May 15, 2015 at 20:13
  • Just wondering, why don't you want drupal to auto resize images? If it's because images can look ugly when width and height values are far apart, you can always use drupal's automatic scale and crop instead of resize. Moreover, you can use some of the croping modules where it allows users to crop the image themselves. Such as SimpleCrop and Imagefield Crop modules.
    – No Sssweat
    May 15, 2015 at 20:25
  • It's because, for example, sometimes i need users upload an image of 1096x180 of a soccer player running, obviously i need to see his face in the picture. If my users upload an image of (example) 1096x900 i cant crop it into 1096x180 cause probably i'll never get the exact place of the image that i need to show. So, when my users upload the image I NEEED to return the message "your image is too big"
    – xstean
    May 18, 2015 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.