Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a js library can can generate a color palette from an image?

Something that might do something like

<img  class="image" ... />

$(".image").get_colors()

I know there are few websites where you can upload your image and it would generate the color for you but I want something to put on my website

Something like this where you see the colors generated from the screenshot and can search by colors. I tried to check the source code but I could not see any reference to a js library.

I need this feature to work with js if possible.

EDIT: The image would be on the page already; I just need to generate its color, so I don't want the uploading features.

Thanks.

like image 579
aurel Avatar asked Dec 07 '11 19:12

aurel


People also ask

How do I find the color palette of an image?

Visit Site. A powerful yet often overlooked feature of Google Image Search is the ability to narrow your results by color. In the nav bar click on search tools and use the color dropdown to filter your images.

How do I make a color palette?

Another quick way to create a really unique color palette is by starting with three colors, for example, purple, orange, and green. You can add another color on top with low opacity, like a light blue. Now that you've created a brand new set of colors that can add so much more dimension to your work.

What is a color palette generator?

Colormind is a color scheme generator that uses deep learning. It can learn color styles from photographs, movies, and popular art. Different datasets are loaded each day, check back tomorrow for even more color inspiration. Visit the blog for tech info or have a look at our API.


1 Answers

You might be interested in this related question and my answer to another one.

Getting all the colors from an image is simple, at least in a browser that supports the canvas element - the technique is described here. You end up with a CanvasPixelArray (described here), which is essentially an array like [r,g,b,a,r,g,b,a, ...] where r,g,b,a are bytes indicating the red, green, blue, and alpha values of each pixel.

The hard part is identifying or creating a small selection of representative colors, rather than the 10,000 colors that might be in a 100x100 image. This is a pretty complicated problem, with many solutions (overview here). You can see Javascript implementations of two possible algorithms in the clusterfck library and my port of the Leptonica Modified Median Cut algorithm.

like image 144
nrabinowitz Avatar answered Sep 22 '22 01:09

nrabinowitz