0

I am loading in external images into my app and I want to get the dominant colour from the image and apply it to a separate div as a background-color in a rgba format

What's the best way to do this?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Axl
  • 67
  • 5
  • possible duplicate of [get average color of image via javascript](http://stackoverflow.com/questions/2541481/get-average-color-of-image-via-javascript) – benek Aug 11 '14 at 16:09

2 Answers2

0

Interesting question. I would say that if possible, any image processing should be done on server side, but if you must do it in javascript, Pixastic is a javascript image library. You can use the histogram function to get an array of colors in the image, then find the most common one from that array.

http://www.pixastic.com/lib/docs/actions/histogram/

chiliNUT
  • 18,989
  • 14
  • 66
  • 106
0

Yes, if the dominant color is simply the most frequently used, I'd just draw it to a canvas element and use getImageData() to determine it.

alex
  • 479,566
  • 201
  • 878
  • 984