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

ファイルアップロード時のブラウザ圧縮のpngのサイズを小さくしたい #11100

Open
tamaina opened this issue Jul 4, 2023 · 7 comments
Labels
✨Feature This adds/improves/enhances a feature

Comments

@tamaina
Copy link
Contributor

tamaina commented Jul 4, 2023

Summary

https://github.com/misskey-dev/browser-image-resizerOffscreenCanvas.convertToBlobを使うが、pngの圧縮が不十分に感じる

もっとpngのサイズを小さくしたい

@tamaina tamaina added the ✨Feature This adds/improves/enhances a feature label Jul 4, 2023
@tamaina
Copy link
Contributor Author

tamaina commented Jul 4, 2023

https://docs.rs/png/latest/png/ をwasmにして使う?

@tamaina
Copy link
Contributor Author

tamaina commented Jul 4, 2023

(とか言ってるとacが言うように変換一式をRustに丸投げしたくなる)

@sorairolake
Copy link
Contributor

PNGの圧縮ならoxipngとかでしょうか?
Wasmにも対応していそうではあります。
shssoichiro/oxipng#194

@tamaina
Copy link
Contributor Author

tamaina commented Jul 4, 2023

#9283

Q. アップロード時はavifにすればいいのでは
A. ブラウザ側の圧縮画像をwebpublicにそのまま利用することでサーバーの負荷を軽減する意図がある。Edgeがavifに対応しないことにはwebpublicをavifにできない

@tamaina
Copy link
Contributor Author

tamaina commented Jul 4, 2023

(サーバーの再変換負荷を受け入れるのであればavifでアップロードしても構わないと思っている。それかMS Edgeを切り捨てるか。)

@acid-chicken
Copy link
Member

#9370 (comment)

@manzyun
Copy link

manzyun commented Jul 10, 2023

釈迦に説法な気がしますが、png形式の圧縮技術の特性上
「色数が少ない画像データに対しては大変圧縮効率が良い」
事は申し上げさせて頂きます:

【画像処理】今さら聞けない画像フォーマット - Qiita
PNG画像の圧縮について - Qiita

裏を返すと、
「うっかりスマホやデスクトップのスクリーンショットを、拡張子を意識せずにアップロードするとそりゃ重い」
という話にもなるかと(大抵 png で保存する為)

拙案

ここまでで思い付いた稚拙な案ですが、下記になります。

  • 画像で使用している色数によって、最適な圧縮方法を選択する。
  • さらに色数とキャンバスサイズによっては、jpgに変換してしまう。

オフトピ

jpgに関しては misskeyでサブモジュールで取得して改変しているソースコードの標準値 を眺める限りは、大変良く攻めた圧縮率を指定していると思います:

あなたのサイトのjpeg画像は過剰品質である。多分。 - Qiita

オフトピ2 WebPという選択肢

これはHTTPサーバーの実装やクライアント側の表示可能精査が必要ですが、WebP・WebMは 2021年の misskey.devサーバーをPC・スマホのFirefoxで閲覧時に表示できたので、これらを用いるのも手かと思います。

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

No branches or pull requests

4 participants