Skip to content

k-wong/Main-Color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 

Repository files navigation

Javascript simple image color extractor

Extracts the main color of a given image, determined by Euclidean distance of RGB values

How it works

  • Creates canvas element of image
  • Loops through subset of pixels and stores colors
  • Finds the distance between each color and all other colors
  • Selects the color with the lowest aggregate distance (RGB values in Euclidean space)

How to use

$('#imgelement').on("load", function() {
	var mainColor = getHex(this);
});
  • Easily extendable - feel free to select the average color of the 10 lowest-aggregate-distance colors

To-do: k-means to find main color

Credit/props:

About

Javascript function to extract main color(s) from images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published