Submit your widget

Images Color Thief with jQuery

Created 12 years ago   Views 15848   downloads 2095    Author lokeshdhakar
Images Color Thief with jQuery
View DemoDownload
67
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!

Usage

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:http://www.lokeshdhakar.com/2011/11/03/color-thief/