3

im creating a way for users to add some buttons to their image. Now i thought it would be cool if the button could change color depending of the background color of the image.

To start with i wanted to go for the black / white contrast.

So if the background is white then the button will be black and if the background color is black then the button should be white.

My question is however is it possible to identify the background of an image using only javascript? and if so how?

Marc
  • 483
  • 3
  • 14
  • 22
  • If you know the URL of the image, you can draw it in a hidden canvas and determine it's dominant color using a library like color thief. – Virus721 Sep 26 '13 at 08:33
  • possible duplicate of [How to use javascript or jQuery to read a pixel of an image?](http://stackoverflow.com/questions/1041399/how-to-use-javascript-or-jquery-to-read-a-pixel-of-an-image) – PP. Sep 26 '13 at 08:33
  • You can draw the image to a `` element, then sample some pixels to detect their color. – pawel Sep 26 '13 at 08:33

0 Answers0