img-color-extractor
v1.0.7
Published
Extract main colors from png
Downloads
110
Maintainers
Readme
img-color-extractor
Node module to extract REAL main colors from a PNG image
REAL mean that if #333333 and #669F64 are the most present colors in a picture, img-color-extractor will extract exactly #333333 and #669F64 and not some color between the two.
Installation
$ npm install --save img-color-extractor
##Usage
const fs = require('fs');
const colorExtractor = require('img-color-extractor');
stream = fs.createReadStream('/test/in.png')
defaultsOptions = {
background: '#FFFFFF',
alphaMin: 0,
dist: 100,
greyVa: -1,
};
// retun a promise resolving an array of objects as:
// [{ color: `hexa`, n: `numberOfOccurrence`, r: `ratio` }, ...]
colorExtractor.extract(stream, opts)
.then(colors => {
console.log(colors) // [ { color: '#ffffff', n: 1515551, r: 0.728368706 },
// { color: '#333333', n: 388783, r: 0.1868478003 },
// { color: '#669f64', n: 174227, r: 0.0837329094 },
// { color: '#b2ceb1', n: 2186, r: 0.0010505842 } ]
});
##Options
background
background color if input has alpha layer. default to'#FFFFFF'
(white)alphaMin
ignore all pixels with alpha layer under alphaMin. default to0
0
keeps all,256
or more removes alldist
distance for regrouping pixels by color. default to100
distance is calculated as sqrt((r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2)`greyVa
ignore all pixels with variance(r, g, b) < greyVa. default to-1
useful to ignore shades of grey-1
keeps all,14451
or more removes all
License
MIT