Resizing images after upload settings


(Paul W) #1

Hi All,
totally confused after reading threads here about image resizing etc.

I’ve set “client_max_body_size” to 102400 in admin->settings-files to allow uploading from cellphones.
But I cannot for the life of me figure out where to set image resizing.

I’ve read some thread:


and

but just cannot get the image to resize.

Help ?


Why is Max image size limited to 100MB?
(Paul W) #2

related question:
Are all uploads sent to /shared/uploads/default/original/1X/ ?

Could I use a convert -resize $WIDTH image.jpg to resize ? perhaps ?


(Régis Hanol) #3

Not sure I understand :thinking:… What are you trying to achieve exactly?

There is no such setting as “client_max_body_size” in Admin > Settings. That’s a NGINX setting.


(Paul W) #4

Sorry. In my haste I posted the wrong thing
I meant max image size kb

I’m trying to scale images from 3400 px wide to something more reasonable


(Régis Hanol) #5

Discourse will automatically create thumbnails for you (we call that process lightboxing). Is that not working?


(Paul W) #6

Ues the thumbnails is working. But the thumbnail Links to the original file that is huge (by default from most phones nowadays)


(Régis Hanol) #7

Oh, you meant resizing the original uploaded image?

The only way to do it right now is via the “max image size kb” site setting.
Whenever a user uploads an image that is larger than this setting, we’ll try to downsize it to fit the setting.

Since it’s CPU/time consuming, we’re only trying to downsize (halving the dimensions) the image 3 times.

If you want another behavior, you’ll have to write a plugin.


(Paul W) #8

Ok cool.
So back to my confusion.
Where do i set this site wide setting?


(Régis Hanol) #9

Like I said, change “max image size kb” to a lower value.


(Paul W) #10

Right … so i set the Max upload in nginx. And the resized size in discourse ?


(Régis Hanol) #11

Pretty much yeah. For nginx, you’ll need to change it via the app.yaml file in order to survive container rebuilds.


(Pad Pors) #12

as far as I know, you should resize images yourself (in your desktop), and discourse will not resize huge images for you.

the setting limits the size of the image one is allowed to upload.


(Stephen Chung) #13

You’re right. Any indication I got from meta is that max image size kb is the maximum allowed uploaded image size. Over this size and the image upload will simply be rejected.

It has been said that Discourse will scale down very large images in the background; how large is very large, and how much to scale down has always remained a mystery.

Now, @zogstrip, does it mean that max image size kb is actually the trigger level for the scale down itself? In other words, if I have:

  • Max upload size in app.yaml = 20MB
  • max image size kb = 1MB

My original understanding is that uploading any image above 1MB will be rejected.

Now @zogstrip is saying that as long as the image is no larger than 20MB it can still be uploaded. But then in the background it will be scaled down (because >1MB), half-dimensioned three times, essentially making it 1/64 of the size?


(Régis Hanol) #14

It’s not a mystery if it’s written in plain text :wink:

Ok, so here’s what happens when a user uploads an image

  • NGINX accepts the image up to its “client_max_body_size” setting (defaults to 10MB, can be overwritten in app.yml)
  • Then, we’ll convert large PNG/BMPs to JPEG to keep the filesize at bay
  • Then, we’ll halve (up to 3 times) the uploaded image until it’s lower than the “max image size kb” site setting
  • If the image is still larger, then we’ll reject it :boom:
  • Then, go on with the upload process (fix orientation, crop, optimize…)

(Stephen Chung) #15

Ah. Clear as mud now. :wink:

So it is not a background job that resizes after-all… It gets done at the time of the upload.


(Stephen Chung) #16

I think the description of the setting needs some serious rewriting:

“The maximum image upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well.”

I don’t think it is accurate AT ALL.


(Jeff Atwood) #17

Sure, what text do you think would make more sense there?


(Stephen Chung) #18

Something like:

Automatically scale down uploaded images to smaller than this size. Images too large to be resized will be rejected. Note: Do not set larger than upload size limit configured in nginx (client_max_body_size) / apache or proxy.


(Jeff Atwood) #19

What do you think @zogstrip?


(Régis Hanol) #20

This might be a bit too verbose for a site setting description but I :heart: the idea.

#pr-welcome :wink: