# Image upload size/resize question

**URL:** https://meta.discourse.org/t/image-upload-size-resize-question/142371
**Category:** Support
**Created:** [February 23, 2020, 4:47am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371 "2020-02-23T04:47:01Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![torsi](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@torsi](https://meta.discourse.org/u/torsi)
#### Post date: [February 23, 2020, 4:47am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/1 "2020-02-23T04:47:01Z")

</div>

After reading through [this topic](https://meta.discourse.org/t/optimize-images-before-uploading/17150), and [this one](https://meta.discourse.org/t/image-upload-max-size-and-further-resizing-regression-issue/60755), and [this one](https://meta.discourse.org/t/image-upload-error-when-using-resizer/142316), 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`?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2020, 5:17am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/2 "2020-02-23T05:17:36Z")

</div>

> [@torsi](#):
>
> 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

This all works out of the box:

 ![1591px-Caerte_van_Oostlant_4MB](https://global.discourse-cdn.com/meta/original/3X/c/c/cce616b640fc4352250416f7f403a35813826092.jpeg)

Right click on ⏫ view source, the image is small. Click on it and you see the full res image.

---

<div class="post-metadata">

### Author: ![torsi](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@torsi](https://meta.discourse.org/u/torsi)
#### Post date: [February 23, 2020, 5:39am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/3 "2020-02-23T05:39:44Z")

</div>

So if I change `max upload` to 10 MB and `max megapixel` to 12, what happens when a user tries to upload a 16 megapixel image that’s 7 MB?

Under the default settings a significant percentage of pictures taken by newer phones are larger than 4096 kB, but nowhere near 40 megapixels.

I’m still not understanding what happens when, or why the defaults are set to what they are.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2020, 5:41am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/4 "2020-02-23T05:41:32Z")

</div>

I recommend playing with the settings, change a setting, upload a huge image, see what happens.

---

<div class="post-metadata">

### Author: ![torsi](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@torsi](https://meta.discourse.org/u/torsi)
#### Post date: [February 23, 2020, 6:14am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/5 "2020-02-23T06:14:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2020, 6:22am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/6 "2020-02-23T06:22:25Z")

</div>

Reading the code, max megapixels is a hard restriction. It is a safety switch not something the system uses to make decisions about downsizing with.

`max_image_size_kb` is the sole deciding factor for auto downsizing on upload.

Bump up max megapixels to the absolute largest amount of megapixels you would ever want to host.

---

<div class="post-metadata">

### Author: ![torsi](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@torsi](https://meta.discourse.org/u/torsi)
#### Post date: [February 23, 2020, 3:42pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/7 "2020-02-23T15:42:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![torsi](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@torsi](https://meta.discourse.org/u/torsi)
#### Post date: [February 23, 2020, 3:48pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/8 "2020-02-23T15:48:17Z")

</div>

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.

---

<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 23, 2020, 7:37pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/9 "2020-02-23T19:37:01Z")

</div>

Thanks for thorough testing with current version. I’ve checked it and it looks like that works in practice just as you described.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2020, 7:48pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/10 "2020-02-23T19:48:06Z")

</div>

Max body size has been 10 for quite a while, we should probably increase it to 20

Agree we should improve the site setting description, will do so later today.

EDIT:

Documentation is updated per:

[https://review.discourse.org/t/doc-improve-documentation-of-image-limit-site-settings/9303](https://review.discourse.org/t/doc-improve-documentation-of-image-limit-site-settings/9303)

---

<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 28, 2020, 2:45am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/11 "2020-02-28T02:45:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 28, 2020, 3:00am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/12 "2020-02-28T03:00:10Z")

</div>

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.

---

<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 28, 2020, 3:09am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/13 "2020-02-28T03:09:30Z")

</div>

> [@sam](#):
>
> Certainly if you push max image size down to 200k, it totally makes sense to just resize the hotlinked images when we download them.

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:

```plaintext
lib/discourse.rb:57:in `exec': convert: improper image header `/tmp/image20200228-23391-t365z9.jpg' @ error/png.c/ReadPNGImage/4294.

```

I wonder if there is a way where DC will always do a resize? Even if the image ends up being tiny?

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [March 8, 2020, 3:20am UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/15 "2020-03-08T03:20:24Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/3X/9/f/9f4d18eb7f95146a3615d17d4a163a35c01a3c8f.png)  
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:

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/9/19c4391687240a8dfdc9ffd76a1a2ce524b7025d.png)  
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.

> [@sam](#):
>
> we should probably increase it to 20

Does this mean the default will soon be changed from 4096 to 20000?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 10, 2020, 8:38pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/16 "2020-03-10T20:38:03Z")

</div>

> [@Change the maximum attachment/upload size](https://meta.discourse.org/t/changing-max-attachment-size/26435):
>
> bookmark This guide explains how to change the maximum attachment upload size for self-hosted Discourse instances. person_raising_hand Required user level: System Admin The default attachment upload size limit is 10MB If you are self-hosting Discourse and need to allow uploads larger than 10 MB, follow the steps below. Changing the upload size Connect to your server: Use SSH to access your server’s command line interface. Edit the configuration file: Navigate to the configurati…

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [March 10, 2020, 8:38pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/17 "2020-03-10T20:38:55Z")

</div>

Brilliant @riking! Thanks, mate!

---

<div class="post-metadata">

### Author: ![vmsman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vmsman/32/215633_2.png) [@vmsman](https://meta.discourse.org/u/vmsman)
#### Post date: [April 3, 2021, 5:22pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/18 "2021-04-03T17:22:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 3, 2021, 7:50pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/19 "2021-04-03T19:50:32Z")

</div>

If there’s nothing in `/var/discourse` you might have an older installation, check `/var/docker` as well.

> [@vmsman](#):
>
> MaxMindDB (/var/www/discourse/vendor/data/GeoLite2-ASN.mmdb) could not be found

Hmm, try rebuilding? You might have an old base image that didn’t handle mmdb key not present correctly.

---

<div class="post-metadata">

### Author: ![vmsman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vmsman/32/215633_2.png) [@vmsman](https://meta.discourse.org/u/vmsman)
#### Post date: [April 3, 2021, 8:35pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/20 "2021-04-03T20:35:42Z")

</div>

Ok, so here’s what those folders look like.

 ![discourse](https://global.discourse-cdn.com/meta/original/3X/f/8/f81459640d16862db53d160f80146af6a8dfcdf8.png)  
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.

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [April 3, 2021, 8:52pm UTC](https://meta.discourse.org/t/image-upload-size-resize-question/142371/21 "2021-04-03T20:52:14Z")

</div>

> [@vmsman](#):
>
> This is a brand new installation

As Jay asks here: [Uploading Files to Discourse - #3 by pfaffman](https://meta.discourse.org/t/uploading-files-to-discourse/185356/3)  
Did you do a [Discourse official Standard Installation](https://meta.discourse.org/t/discourse-official-standard-installation/142537)?

[Next page](https://meta.discourse.org/t/image-upload-size-resize-question/142371.md?page=2)
