5

I'm looking for a way to scan any given image and determine if it is mostly dark or light (in a sense of bright vivid colours or dark and desaturated colours).

This is done in PHP: Background image dark or light?

But is there a way to do it on the fly with Javascript? To look over the pixels and determine their RGBs? I need to know simply whether to style the overlaying text black or white respectively.

Community
  • 1
  • 1
Jody Heavener
  • 2,704
  • 5
  • 41
  • 70
  • 1
    There is a js solution here: http://stackoverflow.com/questions/13762864/image-dark-light-detection-client-sided-script – arnopeck Sep 05 '14 at 14:25

1 Answers1

4

This could be achieved by using HTML5 canvas, as one solution.

Load your image into the canvas, you can then access the pixel values and perform whatever algorithm you choose to use on them

There are no built in commands, that I know of, to do the precise task that you describe.

Another solution would be to serve or read the data into a blob in a raw format, an array of values, so that they can be processed.

Xotic750
  • 22,914
  • 8
  • 57
  • 79