# 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:** 8
**Page:** 2

<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, 11:08am UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/21 "2017-10-27T11:08:35Z")

</div>

If an image can be uploaded, scale it down to smaller than this size, or reject if unable to. Note: Upload size limit is set in nginx / apache or proxy.

EDIT: Should also include `(0 to disable)`.

---

<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, 1:17pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/22 "2017-10-27T13:17:34Z")

</div>

> <https://github.com/discourse/discourse/blob/main/lib/upload_creator.rb#L165>

Actually the down-sizing is done by reducing the number of _pixels_ of the image by half, not by scaling the dimensions by half (which means reducing the number of pixels by 1/4).

And it compares with `max_image_pixels` _BEFORE_ scaling. The correct procedure is to compare with `max_image_pixels` _AFTER_ scaling the first time. Otherwise, the image runs the risk of being made smaller than necessary.

```plaintext
downsized_pixels = [pixels / 2, max_image_pixels].min

```

---

<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, 2:10pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/23 "2017-10-27T14:10:23Z")

</div>

Good point. #pr-welcome 😉

---

<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, 5:59pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/24 "2017-10-27T17:59:20Z")

</div>

> [@zogstrip](#):
>
> Pretty much yeah. For nginx, you’ll need to change it via the app.yaml file in order to survive container rebuilds.

Cool man ! Thanks.

This info isnt clear in the docs..

---

<div class="post-metadata">

### Author: ![uariel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/uariel/32/133167_2.png) [@uariel](https://meta.discourse.org/u/uariel)
#### Post date: [March 6, 2019, 3:37pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/25 "2019-03-06T15:37:23Z")

</div>

Hi! Halving is not working for me. If I upload any file larger than “max image size” I got this:

> Sorry, the image you are trying to upload is too big (maximum size is 1024KB), please resize it and try again.

EDIT: I didn’t see the option " max image megapixels" . But doesn’t help me.

What I want if is possible , is that when a user upload any image larger than 1024KB , then resize until \< 1024KB and delete the original.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 16, 2022, 2:55pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/26 "2022-04-16T14:55:34Z")

</div>



---

<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: [April 17, 2022, 8:16pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/27 "2022-04-17T20:16:57Z")

</div>

Closing this out, as we now resize giant phone images on the client in the editor (that is, on the phone itself, in the browser via JavaScript) courtesy @falco.

---

<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: [April 17, 2022, 8:17pm UTC](https://meta.discourse.org/t/resizing-images-after-upload-settings/72889/28 "2022-04-17T20:17:01Z")

</div>



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