Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
【20250622】クライアントサイドで_ 高品質画像圧縮したいからウェブアプリ版 Squoo...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
asaringo
June 25, 2025
Programming
97
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
【20250622】クライアントサイドで_ 高品質画像圧縮したいからウェブアプリ版 Squoosh参照してwasmに手を出す
間違いあったら優しく教えてください
asaringo
June 25, 2025
More Decks by asaringo
See All by asaringo
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
330
Other Decks in Programming
See All in Programming
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
170
GraphQL の onError と Nullability のこれから
quramy
0
180
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
970
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
250
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
240
golang-bob.pdf
iwatsukayura
0
140
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
240
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
1
200
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
150
Next.js: The final boss of Web Performance
guaca
0
340
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
190
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
460
Featured
See All Featured
Side Projects
sachag
456
43k
Crafting Experiences
bethany
1
390
The Curious Case for Waylosing
cassininazir
1
580
Unsuck your backbone
ammeep
672
58k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Curse of the Amulet
leimatthew05
3
16k
Believing is Seeing
oripsolob
1
250
The Invisible Side of Design
smashingmag
301
52k
Building Adaptive Systems
keathley
44
3.3k
Transcript
クライアントサイドで 高品質画像圧縮したいから ウェブアプリ版 Squoosh 参照してwasmに手を出す 2025/06/22 あさりんご
徒然なるままに… wasmとの出会いを振り返る 結論ありきの順番ではなく、 探索していった時の順番で話してみる (スピーチ結論から話せと言われがちだけどほんとかな? ということでお試ししてみる)
Squoosh Googleが提供しているオープンソースの高品質画像圧縮アプリ ⇒今回はこのオープンソースから、mozjpeg(C言語の高品質画像 圧縮ライブラリ)をwasmにしてjsから呼べるようにしてみる
ここっぽい
すでにwasmのファイルあるっぽいけど、 生成方法は…? ( ゚Д゚) こやつか! 名前的に!
ぐっ… _(´ཀ`」 ∠)_
いったん理解より動かすの優先でいこ Emscriptenを使えるようにするぞ☆ bashで以下コマンドどん git clone https://github.com/emscripten-core/emsdk.git cd /mnt/c/Users/[お名前]/source/repos/emsdk ./emsdk install
latest ./emsdk activate latest source ./emsdk_env.sh 動かしてくうちにわかってくるだろ… ^^) _旦~~
MakefileをEmscriptenに読ませるぞ bashで以下コマンドどん git clone https://github.com/GoogleChromeLabs/squoosh.git cd /mnt/c/Users/[お名 前]/source/repos/squoosh/codecs/mozjpeg/ emmake make
最初makeだけで打っててうまくいかずなんでや…? とかなってた思ひ出 Emscriptenつかうのだから、それ用のコマンドを!
あれ足りないこれ足りない言われる エラー文言に従ってとにかく sudo apt update && sudo apt install [パッケージ名]
できたので使ってみる 生成されたmozjpeg_enc.js ⇒約3000行のコード(;´∀`)コレモウワカンネエナ このjsどうやって使うんや… いったんexportとかないかな ⇒最後の行にexport default Moduleあった ⇒多分importして使えばいいけど、何のメソッドが使えるんや…
これなに?
mozjpeg_enc.cpp⇒バインドファイル Makefileに指定ある バインドファイルを自由に書き換えて何を生成するか決められるんだ jsから何が呼び出せるものかはここ見ればわかるんだ! mozjpeg_enc.cpp Makefile
Mozjpeg_enc.cpp内のコメント • // The code below is basically the `write_JPEG_file`
function from • // https://github.com/mozilla/mozjpeg/blob/master/example.c • // I just write to memory instead of a file. ここ肝である感 I just wirteとかいってるけどめっちゃ大事なことしてくれてる... そこにしびれるあこがれる...☆
使ってみる 生成したmozjpeg_enc.jsとmozjpeg_enc.wasmを 使用したいプロジェクトに連れていく import MozjpegEnc from [ファイルの場所] const mozjpegEnc =
await MozjpegEnc(); const result = mozjpegEnc.encode([画像],[画像の横幅],[画像の 縦幅],[オプション]) ※詳しくはmozjpeg_enc.cpp参照
CanvasAPIで画像圧縮したのと 見た目品質あんま変わらんのやが…(^_^;) • CanvasAPIが使用するのはブラウザ内蔵のjpegエンコーダ/デ コーダ(具体的な実装不明) ⇒こやつ…そこそこ優秀なのでは • オプションをもう少しちゃんといじればよくなる? • そしてCanvasAPIのほうでOKとなったので、
難しいmozjpegとはバイバイしました。
いろいろ新体験 • Emscriptenをつかってみること • chatGPTヘルプもらいつつオープンソースのコードを見てみること • オープンソースから拝借してくること(していいんだ!) • C++に触れる •
個人がGitHubにコードを公開する意味を知る(今度やってみよう)