# Image upload error when using resizer

**URL:** https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316
**Category:** Bug
**Created:** [February 22, 2020, 1:08am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316 "2020-02-22T01:08:47Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 22, 2020, 1:08am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/1 "2020-02-22T01:08:47Z")

</div>

If you try to upload a large PNG which needs to be resized to comply with `max image size kb` you get an error:

```plaintext
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](https://www.dropbox.com/s/auah4bkoipqe9ew/Screenshot%202020-02-21%20at%2014.06.44.png?dl=0)

* * *

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

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [February 22, 2020, 1:25am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/2 "2020-02-22T01:25:27Z")

</div>

> [@AstonJ](#):
>
> 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 [Change the maximum attachment/upload size](https://meta.discourse.org/t/changing-max-attachment-size/26435) for details.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 22, 2020, 2:14am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/3 "2020-02-22T02:14:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 22, 2020, 3:58am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/4 "2020-02-22T03:58:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 22, 2020, 4:32am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/5 "2020-02-22T04:32:50Z")

</div>

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](https://meta.discourse.org/t/optimize-images-before-uploading/17150/51) - so looks like the resizer hasn’t been implemented yet (but I was sure it had 🤔)

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [February 22, 2020, 11:52pm UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/6 "2020-02-22T23:52:14Z")

</div>

> [@AstonJ](#):
>
> Quick search returned [this](https://meta.discourse.org/t/optimize-images-before-uploading/17150/51) - 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.

> [@Image upload max size and further resizing regression issue](https://meta.discourse.org/t/image-upload-max-size-and-further-resizing-regression-issue/60755/17):
>
> 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.

EDIT/UPDATE:

It has been pretty well described here now:

> [@Image upload size/resize question](https://meta.discourse.org/t/image-upload-size-resize-question/142371/7):
>
> 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…

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 24, 2020, 5:55pm UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/8 "2020-02-24T17:55:40Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [March 25, 2020, 11:51am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/10 "2020-03-25T11:51:50Z")

</div>

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...`)

[https://github.com/discourse/discourse/pull/9257](https://github.com/discourse/discourse/pull/9257)

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [March 25, 2020, 11:52am UTC](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316/11 "2020-03-25T11:52:15Z")

</div>


