4

When adding an image field to a content type I can set the minimum sizes under which the image will not upload. I also can set maximum sizes but if the image is bigger the system will resize the image. How can I change this?

I need to set both limits: minimum a maximun sizes. This mean a exact size for the image, then if the image has not the exact size it shouldn't be allow to upload.

enter image description here

  • 2
    downvote? why? Do you mind to spare a few lines to explain why you downvoted my question? – chefnelone Jun 11 '13 at 12:05
  • I didn't vote, but I have to ask: What on earth is the rationale for this requirement? I'd guess the down vote is coming from the request seeming odd. Not that that is a valid reason to down-vote. – Letharion Jun 11 '13 at 12:06
  • I just need that the image has a given size, no scaling, no cropping. Why is this so rare? – chefnelone Jun 11 '13 at 12:08
  • I have no idea, it might be a very common requirement for all I know, I just can't personally see the reason. :) I have +1'd now, btw. – Letharion Jun 11 '13 at 12:10
  • 1
    @chefnelone Typically, image styles are used to force any uploaded image to be a particular size. – mpdonadio Jun 11 '13 at 13:16
3

This is mostly based on memory, so some details might be off.

The image field widget assumes that downsizing an image is a valid action in all cases, so you'll need to override it.

Implementing your own field widget requires a little bit of fiddling with the field api, but since your change is fairly small, you should be able to just wrap a number of image field function and add a single validation step.

Since image field already is mostly a wrapper around a file field, looking at the image field itself for how to implement the above is probably a good start.

| improve this answer | |
0

Simplest but hardcore solution is to disable GD in your PHP. It will disable all built-in scaling and cropping, including the one you don't want here.

Then you could try to re-implement things you want to happen using ImageMagick.

| improve this answer | |
  • 1
    Breaking all forms of scaling and cropping seems like a pretty odd solution to disabling down-scaling on a single field. I don't understand how replacing GD with ImageMagick is helpful in this context. – Letharion Jun 11 '13 at 13:11
  • 1
    @Letharion "If it's stupid but works, it ain't stupid". If no crop or scale is needed in that project, disabling GD is fastest, simplest way to get rid of unwanted scaling. And ImageMagick module is not, as far as I know, a drop-in replacement so enabling it would not restore unwanted behaviour. As for being odd - see quote at the beginning, sometimes putting to much effort only to do things "right way" may be plain waste of time. – Mołot Jun 11 '13 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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