# Resizing images after upload settings

**URL:** https://meta.discourse.org/t/resizing-images-after-upload-settings/72889
**Category:** Self-hosting
**Created:** [October 27, 2017, 1:58am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889 "2017-10-27T01:58:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 1:58am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/1 "2017-10-27T01:58:41Z")

</div>

Hi All,  
totally confused after reading threads here about image resizing etc.

I’ve set “client\_max\_body\_size” to 102400 in admin-\>settings-files to allow uploading from cellphones.  
But I cannot for the life of me figure out where to set image resizing.

I’ve read some thread:

> [@Resize images after uploading](https://meta.discourse.org/t/resize-images-after-uploading/30575/7):
>
> This is now done. We’ll accept images of up to 10MB and then downsize them to the maximum allowed image size leopard

and

> [@Unable to resize images after uploading](https://meta.discourse.org/t/unable-to-resize-images-after-uploading/32183/3):
>
> Ok, I’ve found the bug . It happens that IO.size is cached and while we were actually downsizing the image, the algorithm was always checking the same file size… Thus resulting in an error when uploading a file larger than the image size limit…

but just cannot get the image to resize.

Help ?

---

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 3:09am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/2 "2017-10-27T03:09:04Z")

</div>

related question:  
Are all uploads sent to /shared/uploads/default/original/1X/ ?

Could I use a convert -resize $WIDTH image.jpg to resize ? perhaps ?

---

<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: [October 27, 2017, 8:06am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/3 "2017-10-27T08:06:54Z")

</div>

Not sure I understand 🤔… What are you trying to achieve exactly?

There is no such setting as “`client_max_body_size`” in Admin \> Settings. That’s a NGINX setting.

---

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 8:23am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/4 "2017-10-27T08:23:44Z")

</div>

Sorry. In my haste I posted the wrong thing  
I meant max image size kb

I’m trying to scale images from 3400 px wide to something more reasonable

---

<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: [October 27, 2017, 8:25am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/5 "2017-10-27T08:25:21Z")

</div>

Discourse will automatically create thumbnails for you (we call that process lightboxing). Is that not working?

---

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 8:32am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/6 "2017-10-27T08:32:39Z")

</div>

Ues the thumbnails is working. But the thumbnail Links to the original file that is huge (by default from most phones nowadays)

---

<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: [October 27, 2017, 8:41am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/7 "2017-10-27T08:41:22Z")

</div>

Oh, you meant resizing the **original** uploaded image?

The only way to do it right now is via the “`max image size kb`” site setting.  
Whenever a user uploads an image that is larger than this setting, we’ll try to downsize it to fit the setting.

Since it’s CPU/time consuming, we’re only trying to downsize (halving the dimensions) the image 3 times.

If you want another behavior, you’ll have to write a plugin.

---

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 9:03am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/8 "2017-10-27T09:03:06Z")

</div>

Ok cool.  
So back to my confusion.  
Where do i set this site wide setting?

---

<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: [October 27, 2017, 9:09am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/9 "2017-10-27T09:09:05Z")

</div>

Like I said, change “`max image size kb`” to a lower value.

---

<div class="post-metadata">

### Author: ![TerminalAddict](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terminaladdict/32/119676_2.png) [@TerminalAddict](https://meta.discourse.org/u/TerminalAddict)
#### Post date: [October 27, 2017, 9:24am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/10 "2017-10-27T09:24:58Z")

</div>

Right … so i set the Max upload in nginx. And the resized size in discourse ?

---

<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: [October 27, 2017, 9:33am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/11 "2017-10-27T09:33:55Z")

</div>

Pretty much yeah. For nginx, you’ll need to change it via the `app.yaml` file in order to survive container rebuilds.

---

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [October 27, 2017, 9:41am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/12 "2017-10-27T09:41:07Z")

</div>

as far as I know, you should resize images yourself (in your desktop), and discourse will not resize huge images for you.

the setting limits the size of the image one is allowed to upload.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [October 27, 2017, 10:04am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/13 "2017-10-27T10:04:55Z")

</div>

You’re right. Any indication I got from meta is that `max image size kb` is the maximum allowed uploaded image size. Over this size and the image upload will simply be rejected.

It has been said that Discourse will scale down _very large_ images in the background; how large is very large, and how much to scale down has always remained a mystery.

Now, @zogstrip, does it mean that `max image size kb` is actually the trigger level for the scale down itself? In other words, if I have:

- Max upload size in `app.yaml` = 20MB
- `max image size kb` = 1MB

My original understanding is that uploading any image above 1MB will be rejected.

Now @zogstrip is saying that as long as the image is no larger than 20MB it can still be uploaded. But then in the background it will be scaled down (because \>1MB), half-dimensioned three times, essentially making it 1/64 of the size?

---

<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: [October 27, 2017, 10:13am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/14 "2017-10-27T10:13:15Z")

</div>

> [@schungx](#):
>
> It has been said that Discourse will scale down very large images in the background; how large is very large, and how much to scale down has always remained a mystery.

It’s not a mystery if it’s written in [plain text](https://github.com/discourse/discourse/blob/master/lib/upload_creator.rb) 😉

Ok, so here’s what happens when a user uploads an image

- NGINX accepts the image up to its “`client_max_body_size`” setting (defaults to 10MB, can be overwritten in `app.yml`)
- Then, we’ll convert [large](https://github.com/discourse/discourse/blob/90d6677d97626346ea8e0c6321f19ebda6aeb918/lib/upload_creator.rb#L124) PNG/BMPs to JPEG to keep the filesize at bay
- Then, we’ll halve (up to 3 times) the uploaded image until it’s lower than the “`max image size kb`” site setting
- If the image is still larger, then we’ll reject it 💥
- Then, go on with the upload process (fix orientation, crop, optimize…)

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [October 27, 2017, 10:22am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/15 "2017-10-27T10:22:59Z")

</div>

Ah. Clear as mud now. 😉

So it is not a background job that resizes after-all… It gets done at the time of the upload.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [October 27, 2017, 10:29am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/16 "2017-10-27T10:29:33Z")

</div>

I think the description of the setting needs some _serious_ rewriting:

“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 it is accurate _AT ALL_.

---

<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: [October 27, 2017, 10:29am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/17 "2017-10-27T10:29:54Z")

</div>

Sure, what text do you think would make more sense there?

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [October 27, 2017, 10:33am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/18 "2017-10-27T10:33:13Z")

</div>

Something like:

Automatically scale down uploaded images to smaller than this size. Images too large to be resized will be rejected. Note: Do not set larger than upload size limit configured in nginx (client\_max\_body\_size) / apache or proxy.

---

<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: [October 27, 2017, 10:37am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/19 "2017-10-27T10:37:44Z")

</div>

What do you think @zogstrip?

---

<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: [October 27, 2017, 10:56am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/20 "2017-10-27T10:56:41Z")

</div>

This might be a bit too verbose for a site setting description but I ❤ the idea.

#pr-welcome 😉

[Next page](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889.md?page=2)
