Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress PNG to WebP if non-animated and non-transparent #9370

Closed
saschanaz opened this issue Dec 20, 2022 · 26 comments · Fixed by #11150
Closed

Compress PNG to WebP if non-animated and non-transparent #9370

saschanaz opened this issue Dec 20, 2022 · 26 comments · Fixed by #11150
Labels
✨Feature This adds/improves/enhances a feature

Comments

@saschanaz
Copy link
Member

saschanaz commented Dec 20, 2022

Summary

Following #9277.

For now Misskey only compresses big PNGs to smaller PNGs, but small PNGs are still have significantly large file size compared to lossy formats. A screenshot from a Windows machine with a 1920x1080 display can eat 2 megabytes for example even when such image does not use any alpha value.

One caveat is that the only way to detect transparency from a PNG file is to scan every pixel in JS, which may take some time. 🤔 (Windows uses RGBA without any transparency. 🤷)

Q: Why not WebP?
A: Not usable yet because of Mastodon v3. #9334 (comment)

@saschanaz saschanaz added the ✨Feature This adds/improves/enhances a feature label Dec 20, 2022
@saschanaz saschanaz changed the title Compress PNG to lossy format if non-animated and non-transparent Compress PNG to JPG if non-animated and non-transparent Dec 20, 2022
@saschanaz
Copy link
Member Author

@tamaina What's your point to keep it PNG, btw?

@tamaina
Copy link
Contributor

tamaina commented Dec 20, 2022

@saschanaz

I protest vigorously. I hate lossy images anyway.

@saschanaz
Copy link
Member Author

saschanaz commented Dec 20, 2022

Not even WebP? 👀

This could be an option, but generally I don't think it's a good storage/network use to keep PNG by default.

This could be much cleaner if Mastodon v3 didn't just fail on WebP but at least tried something with its backing ImageMagick 😭

@norz
Copy link

norz commented Jan 1, 2023

The benefits of this proposal far outweigh the drawbacks imho.

@saschanaz
Copy link
Member Author

@tamaina これまだダメです? Windowsでスクリーンショット上げるユーザー少なくないので対応したい

@saschanaz saschanaz changed the title Compress PNG to JPG if non-animated and non-transparent Compress PNG to WebP if non-animated and non-transparent Mar 11, 2023
@tamaina
Copy link
Contributor

tamaina commented Mar 11, 2023

う〜〜ん、低圧縮のlossy webpならいいのかも?

ただwebpをブラウザで実装するのが辛いのか

@saschanaz
Copy link
Member Author

ただwebpをブラウザで実装するのが辛いのか

特に問題ないと思いますが

@acid-chicken
Copy link
Member

@saschanaz
Copy link
Member Author

saschanaz commented Mar 11, 2023

WebP対応出来ているブラウザーではWebPにして他ではそのままにするとかどうでしょう

@acid-chicken
Copy link
Member

iPad をそのままにしてしまうとあまり解決にならないかも image

@saschanaz
Copy link
Member Author

....SafariではJPEGにしてしまえば💢(悪魔の声)

でも他に手あります?そのまま vs JPEGに

@acid-chicken
Copy link
Member

画像周りの話、悩ましいし、ややこしいし、この際 Epic Issue 立てて一旦整理したい……

@saschanaz
Copy link
Member Author

wasm使って全部AVIFにしようって話があったような

@acid-chicken
Copy link
Member

acid-chicken commented Mar 11, 2023

wasm使って全部AVIFにしようって話があったような

理想を言えばこれができると一番嬉しい
デコードの観点ではそのうちメジャーブラウザが全てサポートするようになりそうなのであまり心配がない(連合はまぁ……連合先が対応して欲しいんだけどなぁ)
エンコードの観点では wasm でエンコーダーを持ち込むことでのサポートになるが、実際にやってみてパフォーマンステストしてみないといけない(あと多分 wasm SIMD に対応させないといけない)

@saschanaz
Copy link
Member Author

saschanaz commented Mar 11, 2023

理想と言えばSafariにWebPエンコードをサポートさせるのが理想ですね

一旦はWebPサポートしているブラウザーのみ対応して後は別の件で話したいです(最近のSafariの変化がかなり大きくて希望を持ってもいいかなって)

@acid-chicken
Copy link
Member

一旦はWebPサポートしているブラウザーのみ対応して後は別の件で話したいです(最近のSafariの変化がかなり大きくて希望を持ってもいいかなって)

その方針で良いと思います

@tamaina
Copy link
Contributor

tamaina commented Mar 11, 2023

WebP対応出来ているブラウザーではWebPにして他ではそのままにするとかどうでしょう

iPad をそのままにしてしまうとあまり解決にならないかも

とりあえずSafariはpngにすればいいと思う(iPadのスクショは16bit PNG /w Display P3らしいので、8bit・色域メタデータなしにするだけでも相当軽くなるはず

(本当はavifにしたいんだよな…Mastodon…)

@tamaina
Copy link
Contributor

tamaina commented Mar 11, 2023

でも2MBだから微妙だなぁ

@tamaina
Copy link
Contributor

tamaina commented Mar 11, 2023

toBlob webp、Safariだとquality無視されるけど一応生成できなかったっけ?

@acid-chicken
Copy link
Member

toBlob webp、Safariだとquality無視されるけど一応生成できなかったっけ?

これ本当なら MDN のデータの方修正しようぜ

https://github.com/mdn/browser-compat-data/blame/e74cd55301d99b723aafa7218047511c73ffcafc/api/HTMLCanvasElement.json#L1051-L1084

@acid-chicken
Copy link
Member

@saschanaz
Copy link
Member Author

toBlob webp、Safariだとquality無視されるけど一応生成できなかったっけ?

webpじゃなくPNGが出てきてしまう件について

@saschanaz
Copy link
Member Author

https://html.spec.whatwg.org/multipage/canvas.html#serialising-bitmaps-to-a-file

User agents must support PNG ("image/png"). User agents may support other types. If the user agent does not support the requested type, then it must create the file using the PNG format. [PNG]

仕様だった件

@tamaina
Copy link
Contributor

tamaina commented Mar 12, 2023

なるほど〜〜

@tamaina
Copy link
Contributor

tamaina commented Mar 12, 2023

(エラーにならないんだ…

@acid-chicken
Copy link
Member

若干逸れた話題かもしれないけど、しばらく oxipng を使ってみたところかなりいい感じだった

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨Feature This adds/improves/enhances a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants