Axl
Axl

Reputation: 67

Dominant colour from external image

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?

Upvotes: 0

Views: 205

Answers (2)

alex
alex

Reputation: 490433

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.

Upvotes: 0

chiliNUT
chiliNUT

Reputation: 19573

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/

Upvotes: 0

Related Questions