0.0.1 • Published 7 years ago

node-rgbaster v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Node-RGBaster

Build Status npm version

A simple library for extracting dominant colors from images for Node.js, which is inspired by RGBaster.

Usage

Usage is simple. Use the path of the image file, then get its dominant color & palette.

var rgbaster = require('node-rgbaster');

var imgpath = '/path/to/image.png';

rgbaster(imgpath).then(res => {
    handleSuccess(res);
}).catch(err => {
    handleError(err);
});

Configuration options

The colors function takes an object as optional second parameter, with the following options:

paletteSize

Type: int Default: 10

Maximum number of palette colors to return. Only the top palette colors will be returned.

exclude

Type: array Default: []

RGB colors to exclude when counting colors. For example to exclude white and black use: [ 'rgb(255,255,255)', 'rgb(0,0,0)' ]

then

Type: function

Function to call after image processing has completed. The function will receive one payload argument with the following structure:

{
    // {string} dominant rgb color
    dominant:  'rgb(0,0,0)',

    // {string} secondary rgb color
    secondary: 'rgb(0,0,1)',

    // {array} list of colors in the image (limited by paletteSize)
    palette:   [ 'rgb(0,0,1)', 'rgb(0,0,2)' ]
}

Full example

var rgbaster = require('node-rgbaster');

var imgpath = '/path/to/image.png';

rgbaster(imgpath, {
    paletteSize: 2
}).then(res => {
    console.log(res);
    /*some of the test results
    {
        dominant: 'rgb(111,108,103)',
        secondary: 'rgb(107,104,99)',
        palette: [ 'rgb(107,104,99)', 'rgb(112,109,104)' ]
    }
    */
}).catch(err => {
    throw err;
});

Promise

This package is built in Promise.

License

MIT