After reading through this topic, and this one, and this one, I’m not entirely sure what Discourse does with large images. My previous understanding is that there is no software resizing done, just CSS - that image size was limited by maximum image upload size in kB and that was that. If a larger image is a remote file it gets linked, otherwise you just can’t upload it.
But now I’m confused because those topics mention downsizing and optimizing, which I didn’t think was happening because I’ve never seen it in practice that I’ve been aware of. I also have no idea what the Maximum number of megapixels allowed for an image limit applies to. Does this prevent uploading images larger than that, or do images that exceed that limit get resized so long as they’re < max upload size?
If it’s the latter, why is the default setting for megapixels so huge relative to the default max upload size? It seems extraordinarily unlikely that somebody will want to post a 51 megapixel image that is smaller than 4096 kB.
What I want is for users to conveniently upload whatever they have without worrying about file sizes and resolutions, and for the software to deliver something appropriate that doesn’t kill mobile users and people on slower connections. Is this currently possible just by adjusting max image size and max megapixels?
OK, I can do that. However, I would also like to understand what the software is actually doing so I can make more informed decisions. In the time I’ve been using Discourse I’ve learned to respect the default settings and only change them when necessary. In this instance, the defaults aren’t working very well for a fairly typical community and I am curious why they are set as they are, what reasonable values I should consider instead, and what will happen when I make those changes.
After mashing buttons for awhile to figure things out, this is what I think is happening:
With a default install, client_max_body_size == max image size kb, images will not be resized.
Increasing client_max_body_size will allow larger uploads, which Discourse will then attempt to resize under the limit set in max image size kb
Despite the description which implies otherwise, max image size kb doesn’t actually limit upload sizes (this is super confusing!)
Upload sizes are solely set with nginx’s client_max_body_size
When resizing, JPEG’s stay JPEG’s with good results
PNG’s are converted to JPG’s with acceptable results
Animated GIF’s stay GIF’s with generally lousy results
Is this all correct? If so, it seems like the sort of thing that should be explained a little better since an out of the box installation doesn’t do any image resizing even though that is a feature many people might want and it isn’t clear at all from available documentation how to enable it.
Hmm, I just looked at nginx.sample.conf on github and it seems that the default for client_max_body_size is now 10 MB rather than 4 MB. Has this always been the case? I don’t recall ever making a change to that file on my install before today.
Hi Sam, going by the description there doesn’t seem to be working for me:
+ max_image_size_kb: “The maximum image upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well. Images larger than this and smaller than client_max_body_size will be resized to fit on upload.”
+ max_image_megapixels: “Maximum number of megapixels allowed for an image. Images with a higher number of megapixels will be rejected.”
Or at least no resizing seems to be attempted.
I had max_image_size_kb set to 1000kb and an image slightly over that was replaced by a link and followed by text which says (image larger than 1000KB).
I changed the setting to 500kb and the same thing happened.
I haven’t changed client_max_body_size in NGINX as I assume it is at the default (of 4096).
These are on images that are hot linked btw (where I assume if you have download remote images to local checked) it should treat as a standard upload? (If not can we get it to behave the same way please?)
Edit: Ok so uploading directly and the resizing works - yay! So it’s just the remote images that are being fetched that fail. Not sure what behaviour would be ideal tbh, but on first thought I would think the same - those images get resized too.
I think this is a separate feature request. Certainly if you push max image size down to 200k, it totally makes sense to just resize the hotlinked images when we download them. There are thresholds at play, we should not download a 700 gigabyte image just to figure this out, but yeah something could be a bit better.
I agree Sam. I can’t think of any reason why you wouldn’t want downloaded hot linked images to follow the same rules tbh.
I also just discovered that if you change the max image size, that actually has an impact on what file size you end up with - which is really cool! Setting it to 500kb ended up resizing a 1.2mb image to 360kb, setting it to 200kb, resulted with the same file at 118kb (though obviously it is smaller as well).
Edit: Argh, but we get that original problem again - where images that are too large to be resized fail with:
This is the default setting on our forums. I tried to change it to 20000 and it worked (or appeared to stick), but when I went to upload an image/GIF that was 17.2mb I was greeted with this error message:
Can you tell me what path I would go to (commands to enter) in linux, where I can change the “client_max_body_size” in nginx? I’m on a digitalocean droplet.
Does this mean the default will soon be changed from 4096 to 20000?
/var/discourse only has a shared folder in it. I can’t find the file you speak of. My problem is I have a brand new Discourse installation and no image uploads in posts are working at all. Even as admin, I get the error “Sorry, there was an error uploading that file. Please try again.” i have tried over and over and I get the same error.
Error logs shows:
MaxMindDB (/var/www/discourse/vendor/data/GeoLite2-ASN.mmdb) could not be found: No such file or directory @ rb_sysopen - /var/www/discourse/vendor/data/GeoLite2-ASN.mmdb
Is discourse designed to be a “text-only” discussion group? I have upped all the file settings for max upload to insane sizes and I can’t even upload a 7kb graphic.
I am not sure how to rebuild. Guidance please? This is a brand new installation on a VM and I got absolutely no errors. Everything seems to work except for graphics.