Optimize images before uploading?

Was that given a go?

Another example of what is possible on ImageOptimization in browser:

https://squoosh.app/

This video goes over the tech. They compiled the state of art codecs (the same we use on the server for Discourse) to WASM :exploding_head:

Looks like a cool, optional thing for Discourse.

The WASM for mozjpeg can be compressed to 48k and the WASM for OptiPNG is 93k.

9 лайков

My image folder grows to 42.3 GB.
So I think I need to figure out image processing and storing in Discourse :slight_smile:

1 лайк

I’m not sure if this is the right topic to post on, but I am very interested in knowing if there’s a way to automatically downsize images before they get stored in my discourse. My community is going to be very image heavy.

I’m less than a week in and already 350 MB used and not even open to general public yet. Would like to be able to resize images down to some resolution so that I keep them < 1MB or something like that (based on image resolution though as per norm I think).

I’d recommend using Digital Ocean spaces or S3 for your images so you don’t need to worry about space so much.

It seems unlikely that a community that really likes images is going to want really bad ones. :slight_smile:

We already have max_image_megapixels site setting, can you try toning that down?

2 лайка

@sam Yes, but, the problem is there’s a big difference between reducing some resolution that most people won’t even notice (IMO big diminishing returns), versus blocking them from uploading at all. On my main site, I downsize to 1500x and no one cares. But if they can’t upload it’s a huge hassle.

@pfaffman This sounds perfect, I guess I need to read:

I wonder, this is probably something I need to do sooner than later, because I’m guessing trying to migrate the files from discourse hosting to s3 could be hard?

1 лайк

I do support a simpler mechanism longer term, something like

All images must be smaller than 500k but allow people to upload stuff up to 2000k and fix on server if needed by either downsizing or reducing resolution. Try resizing on client first if possible.

But yeah, getting to this level of fidelity will take quite a while.

2 лайка

There is a rake task that will do it, but I’d say that sooner is better than later. :slight_smile:

1 лайк

Большинство наших пользователей используют мобильный интернет, и иногда скорость их соединения может составлять 3G или ниже. Во многих случаях качество отправляемых ими изображений не так важно, как скорость передачи.

При загрузке через 3G (около 2 Мбит/с) отправка изображения размером 5 МБ занимает примерно 20 секунд, и это время может значительно увеличиться при снижении скорости.

Как отмечает @Falco, с помощью аналогичных алгоритмов размер изображения в 5 МБ можно уменьшить до 190 КБ за счёт сжатия на стороне клиента и снижения разрешения. Это позволит ускорить отправку (в сети 3G — около 1 секунды) и сократить потребление ресурсов.

На скриншоте выше показан процесс отправки изображения в мессенджере Telegram

Есть ли такая функция в плане разработки (Roadmap)? Если да, то когда её можно ожидать — скоро или в отдалённой перспективе?

Мы в конечном итоге хотим это реализовать, но в нашей публичной дорожной карте на странице #releases этого пока нет.

На этой неделе я напишу RFC по этой функции, чтобы мы могли двигаться дальше, хотя бы на уровне спецификации.

7 лайков

Это уже возможно в iOS. Вот как (скриншот будет, подождите)

Через

Я выбрал «большой». Но ориентация всё равно сбивается!

7 лайков

Спасибо, это здорово :pray: :+1:

Хотелось бы, чтобы Android тоже научился :sweat_smile:

В дополнение к этой функции лайтбокс может быть кнопкой для вращения изображения

Эта библиотека выглядит интересно: GitHub - silvia-odwyer/photon: ⚡ Rust/WebAssembly image processing library · GitHub

Бинарный файл в формате wasm кажется идеальным выбором, так как он будет быстрым и энергоэффективным.

3 лайка

Мне интересно, окажет ли сжатие изображений на стороне клиента, когда это возможно, заметное влияние на производительность веб-сервера при использовании хостинга со скромными характеристиками (например, общий CPU на DigitalOcean).

Я периодически наблюдаю всплески использования процессора, которые, как мне кажется, связаны с загрузкой пользователями изображений, требующих сжатия. Кто-нибудь сталкивался с подобным влиянием?

2 лайка

Обсуждение реализации на Optional image optimization before upload

1 лайк