Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurymind/c686a574e72876e933a07dc040ebf70e to your computer and use it in GitHub Desktop.
Save blurymind/c686a574e72876e933a07dc040ebf70e to your computer and use it in GitHub Desktop.
Remove alpha channel on a canvas, so it's always transparent or always opaque
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pixels = imageData.data;
for (let i = 3, n = canvas.width * canvas.height * 4; i < n; i += 4) {
pixels[i] = pixels[i] < 127? 0 : 255
}
ctx.putImageData(imageData, 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment