Image upload error when using resizer

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?)

1 Like

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.

5 Likes

I changed 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”?

5 Likes

The error message is really bad, though I wonder how many people change that setting in the first place?

5 Likes

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 :thinking:)

1 Like

That was my understanding too… that there is downsizing in place that processes large upload on the server.

EDIT/UPDATE:

It has been pretty well described here now:

5 Likes

@udan11 can you find a way to have a better error message when a user is trying to upload a very large image? Low priority.

4 Likes

I fixed the two problems here:

  1. The image optimization pipeline converted PNGs to JPEGs and then tried to optimize resulted JPEGs using the operations for PNG images.

  2. ImageMagick errors were returned to the user, but were not helpful at all (e.g. convert: improper image header...)

8 Likes