Submit your widget

Images Color Thief with jQuery

Created 12 years ago   Views 15849   downloads 2095    Author lokeshdhakar
Images Color Thief with jQuery
View DemoDownload
Share |

Ever wanted to grab the dominant color or color palette from an image?… Probably not. But now you can!

Usecase #1: Color Search

This script could be useful for sites that sort and search by color. But you should probably save your user’s computer some work and handle the color processing on the server. A couple of color search site examples:

Usecase #2: Color Adapting UI

With this script you can build a UI that adapts to the colors of an image. For example, you could add color accents to the UI by changing the font or border color depending on what image is currently being displayed in your portfolio. To get a bit fancier you could darken the dominant color and use it as a background color or invert the dominant color and use it as the text color. Fancy indeed!


Grab the code from Github. Include jquery, quantize.js, and color-thief.js on your page. Then add something similar to the following:

myImage = $('#myImage');
dominantColor = getDominantColor(myImage);
paletteArray = createPalette(myImage, 10); // 2nd argument sets the # of colors in palette

That’s the gist of it. For more information, your best bet is to dig through the code.

Read more: