Is it possible to determine if a given image is grayscale or color using JavaScript?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Take a look at http://www.pixastic.com/lib/docs/actions/colorhistogram/
This will easily provide the data you need to determine this.
回答2:
draw image to canvas
loop through image data
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.