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?
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?
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.
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.