get-rgba-palette
Gets a palette of prominent colors from a flat array of RGBA pixels.
Full example:
var palette = var pixels = var load = var baboon =
Returns RGB colors in the form of:
[ [255, 0, 0], [128, 23, 52], [124, 0, 62], etc.. ]
Usage
palette(pixels[, count, quality, filter])
Gets an array of RGB colors from an image (pixels
is a flat RGBA array). Defaults to a count
of 5 colors and a quality
setting of 10.
quality
determines the step between each pixel when computing the quantization; higher number means fuzzier quality. Must be > 0.
filter
allows you to threshold the RGBA values given to the quantize function. It passes (pixels, index)
-- the flat array and index to the RGBA component. Return true to accept the color, or false to reject.
If not specified, the filter function defaults to:
{ // offset 3 --> alpha return pixelsindex + 3 >= 127}
palette.bins(pixels[, count, quality, filter])
Instead of returning RGB colors, this returns the "bins" for each computed color. This can give you a very rough overview of the distribution of colours in the image. This is fairly arbitrary as the bin size
does not always represent the exact number of pixels for that color in the image.
Returns an array of objects:
color: 255 0 0 size: 12414 amount: 065
Where amount
is a percentage for that bin, normalized from the sum of the sizes in the returned bins.
License
MIT, see LICENSE.md for details.