I am trying to build something like this or this. In order to reduce the filesize I want to separate on colorchannel and then grayscale it, similar to the channel separate command in Imagick convert rose: -channel R -separate separate_red.gif
So my code looks like this
var imageData = ctx.getImageData(0,0,cw, ch);
var data= imageData.data
for (var i = 0; i < data.length; i += 4) {
data[i] = 0; // red
data[i + 2] = 0; // blue
}
for (var i = 0; i < data.length; i += 4) {
var grayscale = data[i]*0.2126 + data[i +1]*0.7152 + data[i +2]*0.0722;
data[i] = grayscale; // red
data[i + 1] = grayscale; // green
data[i + 2] = grayscale; // blue
}
ctx.putImageData(imageData, 0, 0);
}
with the first for
loop I am grabbing the green color channel and then in the second I grayscale it.
That works for png with transparent background, however if they have white background they turn into a dark grey. How do I turn that off? IS there something wrong with the alphachannel?
Thanks in advance