I'm leveraging some of the the code from the following selected answer:
How to change color of an image using jquery
It's working very well, but when I run the code more than once, it seems like the new color is being added to the old color, so eventually everything turns black. I think my problem is not really understanding what's happening on this piece:
for(var I = 0, L = originalPixels.data.length; I < L; I += 4)
{
// If it's not a transparent pixel
if(currentPixels.data[I + 3] > 0)
{
currentPixels.data[I] = originalPixels.data[I] / 255 * newColor.R;
currentPixels.data[I + 1] = originalPixels.data[I + 1] / 255 * newColor.G;
currentPixels.data[I + 2] = originalPixels.data[I + 2] / 255 * newColor.B;
}
}
I understand that I'm looping through all the pixels on the canvas and modifying the non-transparent ones, but what, for example is the pixel data / 255 * the new red, green or blue?