Skip to content

Dominant color extraction from RGB images—DOM port of Ole Krause-Sparman's algorithm

License

Notifications You must be signed in to change notification settings

amonks/colorcube-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

colorcube.js

This is a JavaScript port of ColorCube, by Ole Krause-Sparmann. You can find an excellent description of how it works at that repo

ColorCube is for dominant color extraction from RGB images. Given an image element, it returns a sorted array of hex colors.

usage

var cc = new ColorCube( // all arguments are optional; these are the defaults:
  20,   // color-space resolution
  0.2,  // brightness threshold
  0.4   // distinctness threshold
);
var image = document.getElementById("image");
var colors = cc.get_colors(image);

info/caveat

colorcube-js has no dependencies. Not even jQuery! However...

colorcube-js's source uses several ES6 features (default arguments, for/of, let, arrow functions ((for lexical this)) ). The files in dist have been automagically run through babel, which makes it run in current versions of Chrome and Firefox. (Not even Chrome Canary can handle the un-babelfied code).

Even with Babel, colorcube still uses Symbol, which is supported by current versions of Chrome and Firefox but not Safari.

There are multiple polyfills available to add Symbol to browsers that don't support it natively. es6-symbol is likely the smallest.

In the demo page, I use core-js because it was easy to CDN in.

Babel maintains their own polyfill, which would work also.

alternatives

There are several other options for in-browser color extraction. I like this one best because it is small and easy to understand. (Props again to Ole Krause-Sparmann for the excellent algorithm).

About

Dominant color extraction from RGB images—DOM port of Ole Krause-Sparman's algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published