Resizing images after upload settings

If an image can be uploaded, scale it down to smaller than this size, or reject if unable to. Note: Upload size limit is set in nginx / apache or proxy.

EDIT: Should also include (0 to disable).

2 Likes

https://github.com/discourse/discourse/blob/master/lib/upload_creator.rb#L165

Actually the down-sizing is done by reducing the number of pixels of the image by half, not by scaling the dimensions by half (which means reducing the number of pixels by 1/4).

And it compares with max_image_pixels BEFORE scaling. The correct procedure is to compare with max_image_pixels AFTER scaling the first time. Otherwise, the image runs the risk of being made smaller than necessary.

downsized_pixels = [pixels / 2, max_image_pixels].min
4 Likes

Good point. #pr-welcome :wink:

1 Like

Cool man ! Thanks.

This info isnt clear in the docs…

Hi! Halving is not working for me. If I upload any file larger than “max image size” I got this:

Sorry, the image you are trying to upload is too big (maximum size is 1024KB), please resize it and try again.

EDIT: I didn’t see the option " max image megapixels" . But doesn’t help me.

What I want if is possible , is that when a user upload any image larger than 1024KB , then resize until < 1024KB and delete the original.

2 Likes