How the PNG compressor works
Most PNGs are saved as full 24-bit or 32-bit colour even when the picture uses far fewer distinct colours. This compressor builds a palette of at most the number of colours you choose, maps every pixel to its closest palette entry and writes an indexed PNG, which is often 50–80% smaller for screenshots, logos and illustrations. Transparency travels with the palette, so soft edges and drop shadows survive.
The palette comes from a median cut followed by a few k-means refinement rounds, done in premultiplied colour space so that semi-transparent pixels are matched by how they actually look. Fully transparent pixels always keep an entry of their own.
The optional second pass runs oxipng, a lossless optimiser compiled to WebAssembly, which tries different row filters and compression settings and keeps the smallest. If a result would not be smaller than your original, the original is kept.