# Optional image optimization before upload

**URL:** https://meta.discourse.org/t/optional-image-optimization-before-upload/187656
**Category:** Feature
**Tags:** rfc
**Created:** [April 21, 2021, 5:12pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656 "2021-04-21T17:12:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 21, 2021, 5:12pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/1 "2021-04-21T17:12:25Z")

</div>

Continuing the discussion from [Optimize images before uploading?](https://meta.discourse.org/t/optimize-images-before-uploading/17150):

This is a RFC for opt-in image compression/resize/optimization on the client side before the upload process. This will be experimented with using a theme-component. If proven useful, we will consider adding this feature in core for 2.8.

### UI

Users will be able to control client side optimization via a simple checkbox in the upload modal

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/7/17df7d0944bc1ded7c3d25a756423b9aaf3cb75c.png)

### Compression tech

At first we will experiment optimizing JPEGs, which are the most common uploads from users smartphones.

Our component will re-size the user upload if it’s larger than the max configurted size and re-encode it using MozJPEG.

In my tests this takes \<10s in a mid-range Android phone, and compresses a typical photo to less than 30% of its original size.

### Results

Original

 ![PXL_20210311_210205783375x500, 100%](https://global.discourse-cdn.com/meta/original/3X/7/a/7ab0680d6cf33fa91b8a6ef71612e937b0706dbd.jpeg)

Optimized

 ![PXL_20210311_210205783(2)375x500, 100%](https://global.discourse-cdn.com/meta/original/3X/8/8/881d070827bfcc5125c54694859d39b0e603bc8a.jpeg)

Resized to 50% + Optimized

 ![PXL_20210311_210205783(1)375x500, 100%](https://global.discourse-cdn.com/meta/original/3X/f/7/f754abfd334e6d740bdab4aa2cff966cb7cd6d1d.jpeg)

---

<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: [April 22, 2021, 1:48am UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/2 "2021-04-22T01:48:14Z")

</div>

I am not sure if this should be an end user option, especially since they might just be cutting and pasting. Instead I think this is a site-operator kind of thing.

> How much should images be optimized prior to uploading: “noting|a bit|a lot” …

Name/value and default pending.

The results look quite excellent! Also, in combination… maybe we make this 100% automatic for certain cases? You set the “maximum” size of images on your forum to 2000KB and we have a heuristic that kicks in and makes sure we take care of stuff.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 23, 2021, 12:47am UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/3 "2021-04-23T00:47:49Z")

</div>

> [@Falco](#):
>
> this takes \<10s

A progress indicator would be very helpful here in case of multi-image uploads to let the user know something is happening.

> [@sam](#):
>
> make this 100% automatic for certain cases

Yes, please. Left up to users it will be used sporadically and non-savvy users will not understand the purpose.

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [April 23, 2021, 2:02am UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/4 "2021-04-23T02:02:57Z")

</div>

A tool I like with 75 quick compression [https://squoosh.app/](https://squoosh.app/)

---

<div class="post-metadata">

### Author: ![AdamAndrews](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@AdamAndrews](https://meta.discourse.org/u/AdamAndrews)
#### Post date: [May 28, 2021, 7:58pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/5 "2021-05-28T19:58:44Z")

</div>

It would be useful to have this as an admin option to enable where anything that exceeds site’s dimension/size settings gets automatically compressed. For more image intensive sites wouldn’t want this on all the time, but instead to cover use cases where less savvy users don’t need to worry about resizing.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 22, 2021, 9:09pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/6 "2021-06-22T21:09:48Z")

</div>

This feature is almost ready, we should be able to test it soon:

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

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 23, 2021, 9:44pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/7 "2021-06-23T21:44:48Z")

</div>

Please check [Testing composer image optimization](https://meta.discourse.org/t/testing-composer-image-optimization/194841)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 23, 2021, 9:44pm UTC](https://meta.discourse.org/t/optional-image-optimization-before-upload/187656/8 "2021-06-23T21:44:51Z")

</div>


