Image Quantize
Reduce an image to a fixed number of colors (octree).
Overview
The Image Quantize tool reduces an uploaded image's colour count to a fixed palette using an octree algorithm. Pick a target palette size — typically between 2 and 256 — and the tool returns a re-encoded copy with every pixel snapped to the nearest palette entry. The result looks similar to the original at higher palette sizes but turns into clean, indexed-colour artwork as the count drops.
It is essential when targeting indexed-colour formats like GIF, when generating retro game sprites from a high-fidelity render, or when shrinking PNG files where deflate compresses indexed pixels much better than 24-bit RGB. Many low-bandwidth UIs use this as a colour reduction step on icons online.
How it works
The octree algorithm builds an 8-level tree where every node represents a region of RGB space. Each pixel is inserted by routing its bits through the tree (the most-significant bit of each channel chooses the root child, and so on). When the leaf count exceeds the target palette size the tree merges its least-populated leaves into their parents, collapsing rare colours into nearby common ones.
After merging completes, each surviving leaf is one palette entry — its colour is the average of every pixel that landed in it. The tool then walks the image a second time and assigns each pixel the closest palette entry. Optional Floyd-Steinberg dithering can be layered on top to hide banding at very low palette sizes.
Examples
Before: photo.jpg, ~140,000 unique colours
After: photo.png, 64-colour palette — looks identical at thumbnail
size, banded under close inspection.
Before: logo.png with anti-aliased edges (3,200 unique colours)
After: logo.png with a 16-colour palette — vector-like flat regions,
crisp boundaries.
Before: screenshot.png (8,500 colours)
After: screenshot.gif (32-colour palette, far smaller file)
FAQ
When should I pick octree over median-cut?
Octree is fast and produces a deterministic palette that tracks the image's colour distribution well. Median-cut sometimes preserves rare hues better but is slower. For most production work octree is the right default.
Does quantising lose alpha?
No — alpha is preserved as a separate channel or, for indexed-colour PNG, as one or more transparent palette entries.
Should I dither after quantising?
Yes for photographs at small palettes (under 32 colours) — dithering smooths the banding. For logos and UI sprites, undithered output looks cleaner.
Will the file size shrink?
Usually yes — indexed PNGs are typically half the size of their 24-bit equivalents, and GIFs compress LZW more efficiently when the palette is tighter.
Can I supply a fixed palette?
The bundled implementation derives the palette automatically. A fixed-palette quantise (e.g. snapping to a brand-approved colour set) requires a separate nearest-colour mapping pass.