How it works
- Image is loaded into a hidden canvas and downscaled to 200px on the long edge.
- Each pixel's RGB channels are snapped to 5 bits (32 levels per channel = 32,768 buckets).
- Buckets are tallied; the N most-frequent are returned with their averaged centre colour.
- Transparent pixels (alpha < 200) are excluded so cut-outs don't pollute the palette.
It's a frequency-based quantiser — fast, simple and dependency-free. For perceptually-tighter palettes use a k-means tool.