0.0.11 • Published 4 years ago
palette-simple
Licence
MIT
Version
0.0.11
Deps
1
Size
235 kB
Vulns
0
Weekly
0
palette-simple
generate reduced color palette versions of an image
uses skmeans clusters
Installation
npm i palette-simple
Usage
var imgPalette = require('palette-simple').imgPalette;
var img = require('image-sync').read('./cat.png');
var numberOfColors = 8;
//imgPalette(data, numberOfColors, skipBuildImage=false) //data is flat uint8 array [r,g,b,a,r,g,b,a ... ]
var dataPalettized = imgPalette(img.data, numberOfColors); //returns {palette, data}
var theColorPalette = dataPalettized.palette;
console.log(theColorPalette);
// palette with 8 colors
// [
// [ 158, 130, 122 ],
// [ 97, 71, 65 ],
// [ 200, 175, 165 ],
// ...
// ]
img.data = dataPalettized.data;
img.saveAs('./cat2.png');

2 colors

4 colors

8 colors

16 colors

32 colors

original
