If you try to upload a large PNG which needs to be resized to comply with
max image size kb you get an error:
lib/discourse.rb:57:in `exec': convert: improper image header `/tmp/image20200221-243-17ldizm.jpg' @ error/png.c/ReadPNGImage/4294.
If you change the extension of the image to
.jpeg it uploads fine!
It also works fine if you reset
max image size kb to the default, however, it seems to be renaming the image as a jpeg regardless.
Here’s the image:
Dropbox - Screenshot 2020-02-21 at 14.06.44.png - Simplify your life
Edit: I’ve also just noticed this under the
max image size kb option:
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 I’ve done that - could it be causing it? (any examples on where to edit this?)
It should be possible to increase that value by adding an
upload_size parameter to your site’s
app.yml file. See
Changing Max Attachment Size for details.
max image size kb to 500k and it uploaded, I wonder though if the error message shown to users should simply be something like “Upload failed: image size too large, please resize and try again”?
The error message is really bad, though I wonder how many people change that setting in the first place?
I can’t remember for sure now, but IIRC if you lower that setting and an uploaded image is larger than that, Discourse will attempt to resize the image to bring it down.
I think it’s tied to the
png to jpg quality setting? It was a while ago now but I think Sam worked on the image resizer.
With regards to anyone who’d want to change it (or rather want smaller image sizes) I’d imagine any site where image quality is less important (so most sites apart from photography sites).
Quick search returned
this - so looks like the resizer hasn’t been implemented yet (but I was sure it had )
That was my understanding too… that there is downsizing in place that processes large upload on the server.
Yup, we already do that.
We don’t have a maximum allowed upload size site setting though. It’s only limited via NGINX.
And we also have another site setting to help downsize images: max image megapixels.
It has been pretty well described here now:
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 w…
@dan can you find a way to have a better error message when a user is trying to upload a very large image? Low priority.
I fixed the two problems here:
The image optimization pipeline converted PNGs to JPEGs and then tried to optimize resulted JPEGs using the operations for PNG images.
ImageMagick errors were returned to the user, but were not helpful at all (e.g.
convert: improper image header...)