huey

A little utility that finds the dominant colour or palette of an image.

huey

huey is a little utility that finds the dominant colour or palette of an image. It works on the server as well as in the browser, and there’s also a command-line version.

http://michaelrhodes.github.io/huey/

$ npm install [-g] huey
var image = require('get-image-data')
var dominant = require('huey/dominant')
var palette = require('huey/palette')
 
image('./image.jpg', function (errorimg) {
  console.log(dominant(img.data))
  // => [124, 51, 21] 
 
  console.log(palette(img.data, 2))
  // => [[121, 50, 23], [243, 21, 23]] 
})

You should really only require code you need, but if you want the kitchen sink…

var huey = require('huey')
 
huey('./image.jpg', function(errorrgbimage) {
  var red = rgb[0]
  var green = rgb[1]
  var blue = rgb[2]
 
  // In case you want to do something 
  // with the raw image data. 
  console.log(
    image.data,
    image.height,
    image.width
  )
})
 
huey.palette('./image.jpg', 2, function(errorpaletteimage) {
  palette.forEach(function (rgb) {
    var red = rgb[0]
    var green = rgb[1]
    var blue = rgb[2]
  })
 
  // In case you want to do something 
  // with the raw image data. 
  console.log(
    image.data,
    image.height,
    image.width
  )
})
$ huey /path/to/image
=> r, g, b

huey depends on get-image-data, which in turn depends on node-canvas. Although node-canvas is a great project, its dependencies can make it hard to install. If you run into problems, I recommend checking out their install guides on the node-canvas wiki.

MIT