palette-simple

0.0.11 • Public • Published

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
2 colors

4 colors
4 colors

8 colors
8 colors

16 colors
16 colors

32 colors
32 colors

original
original

See Also





stonks

Package Sidebar

Install

npm i palette-simple

Weekly Downloads

0

Version

0.0.11

License

MIT

Unpacked Size

240 kB

Total Files

5

Last publish

Collaborators

  • stonkpunk