InterfaceQuantizeOptions

Options of Image.quantize: either colors or palette, and the dithering

interface QuantizeOptions {
    colors?: number;
    dither?: "none" | "floyd-steinberg" | "atkinson" | "ordered";
    ditherStrength?: number;
    palette?: number[];
}

Properties

colors?: number

The number of colors to reduce the image to, an integer from 2 to 256. The palette is the image's own colors when it has no more distinct ones than this, else colors chosen by median cut (the common colors get their own). Those are averages of groups of similar colors, so e.g. pure black and white are only in it if the image has them in quantity: give palette for exact colors. Default: 256. Give colors or palette, not both

dither?: "none" | "floyd-steinberg" | "atkinson" | "ordered"

How the rounding error of each pixel is handled, which makes gradients look smooth with few colors: 'none' (each pixel takes its nearest color), 'floyd-steinberg' (the error goes to the next pixels, 7/16, 3/16, 5/16 and 1/16), 'atkinson' (the error goes to six neighbours, 1/8 each: lighter, more contrast), 'ordered' (a regular 4x4 pattern of thresholds, no error spreading). Rows alternate direction for the error diffusions. Default: 'none'

ditherStrength?: number

How strongly to dither, from 0 (no spreading or threshold, the same as 'none') to 1 (the full error or threshold). Default: 1

palette?: number[]

A fixed palette (1 to 256 colors, e.g. a Game Boy's four greens) that every pixel is mapped to, the nearest color by its RGB. The alpha of the palette's colors is ignored. Give palette or colors, not both