Browser Canvas Technique Fits Transparent 128x128 PNGs Under 128 KB
Canvas 2D's toBlob ignores the quality parameter for PNG, so developers cannot reduce file size natively when targeting strict limits like Slack's 128 KB emoji cap. A 128x128 RGBA image can exceed that ceiling once PNG encoding and compression are applied, especially with noisy or gradient-heavy artwork. The article proposes a pure TypeScript approach avoiding large WebAssembly codecs, combining background removal with palette reduction. Background keying uses a corner-seeded breadth-first flood fill, which spares enclosed foreground details that naive global color thresholding would erase. Ordered Bayer dithering and alpha-preserving quantization then reduce unique color values until the output fits the size budget.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in