Grabs the dominant color or a representative color palette from an image. Uses javascript and canvas.
Pull request Compare This branch is 51 commits behind lokesh:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
css
img
js
sass
.gitignore
README.markdown
index.html
index.js

README.markdown

Color Thief

A script for grabbing the dominant color or color palette from an image. Uses javascript and canvas.

See a Demo | Read more on my blog

Usage

Get Dominant Color

getDominantColor(sourceImage)
returns [num, num, num]

Uses the median cut algorithm provided by quantize.js to cluster similar colors and return the base color from the largest cluster.

Create Palette

createPalette(sourceImage, colorCount)
returns [ [num, num, num], [num, num, num], ... ]

Use the median cut algorithm provided by quantize.js to cluster similar colors.

License

by Lokesh Dhakar | lokeshdhakar.com | twitter.com/lokeshdhakar

Thanks to jfsiii for a large number of code improvements and others for submitting issues and fixes.

Licensed under the Creative Commons Attribution 2.5 License

  • Free for use in both personal and commercial projects.
  • Attribution requires leaving author name, author homepage link, and the license info intact.