Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if image is Grayscale or Color using JavaScript?

Is it possible to determine if a given image is grayscale or color using JavaScript?

like image 824
devnull Avatar asked Nov 30 '11 16:11

devnull


2 Answers

  1. draw image to canvas

  2. loop through image data

  3. test for each pixel if red-cahnnel == green-channel == blue-channel (all color-channels have the same value)

if true for all pixels it is grayscale, if you hit the first pixel that does not meat the condition you can stop and it is color.

like image 79
zuloo Avatar answered Sep 21 '22 17:09

zuloo


Take a look at http://www.pixastic.com/lib/docs/actions/colorhistogram/

This will easily provide the data you need to determine this.

like image 37
tkone Avatar answered Sep 24 '22 17:09

tkone