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.…