Menu

Fitting animated stickers under 512 KB in the browser with Rust and WebAssembly
📰

Fitting animated stickers under 512 KB in the browser with Rust and WebAssembly

DEV Community: rust·abhaysingla05·2 days ago
#r4IOZ9kW
#devtorust#devto#dev#frame#apng
Long article (328 words) — no AI summary yet.
Reading 0:00
15s threshold

Discord's custom asset limits are notoriously tight: 320×320 px under 512 KB (APNG or PNG) for stickers, and 128×128 px under 256 KB (PNG or GIF) for emojis.

Standard image compressors usually fail here for two reasons:

They optimize for visual quality, not a hard byte ceiling. Running oxipng or gifsicle once might shrink a 1.8 MB animation to 720 KB—still rejected on upload.

APNG and GIF have completely different compression bottlenecks. An APNG stores full 32-bit RGBA frames unless you quantize each frame's palette or use lossy alpha/color reduction; a GIF is already capped at 256 colors per frame, so bloat comes from frame count, inter-frame disposal, and dithering noise.

Solving it client-side with Rust + WebAssembly

Instead of uploading user assets to a backend queue, you can run a bounded search loop directly in the browser using Rust compiled to WebAssembly:

Normalize dimensions & frame rate first.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.