README
domcolor
Get the dominant color from an image.
Installation
npm install domcolor
Usage
domcolor (args)
args:<string>|<Buffer>(Required)The string path to the source image or the source image in buffer form.
argsis a required parameter.Returns:
<Object>rgb:<Array>color RGB valueshex:<string>color in hex formatcount:<integer>the number of pixels are the dominant colortotal:<integer>the total number of pixels in the image
Sample Code
/* example usage */
;(async function whatColor () {
try {
let domcolor = require('domcolor')
let fromPath = await domcolor('/path/to/my/cat_pic.jpg')
/* OR */
let imgBuffer = fs.readFileSync('/path/to/my/cat_pic.jpg')
let fromBuffer = await domcolor(imgBuffer)
console.log(fromPath, fromBuffer)
} catch (error) {
console.error(error)
}
})()
/* getting hex from file -- condensed */
;(function getBackgroundColor (cb) {
require('domcolor')(require('fs').readFileSync('/path/to/img.jpeg'))
.then(cb)
.catch(console.error)
})(({ hex }) => console.log('hex:', hex))
Example

{ rgb: [ 208, 182, 152 ], hex: '#d0b698', count: 23210, total: 65536 }

Contributing
See our guidelines, in Contributing.