Skip to content

Instantly share code, notes, and snippets.

@vegeta897
Created February 9, 2018 20:49
Show Gist options
  • Save vegeta897/94cc49ac3bf953917732e65b5958f472 to your computer and use it in GitHub Desktop.
Save vegeta897/94cc49ac3bf953917732e65b5958f472 to your computer and use it in GitHub Desktop.
function applyAlpha(source, target) {
var sourceData = source.getContext('2d').getImageData(0,0,source.width,source.height),
targetCtx = target.getContext('2d'),
targetData = targetCtx.getImageData(0,0,target.width,target.height);
for(var p = 3; p < targetData.data.length; p += 4) {
targetData.data[p] = sourceData.data[p];
}
targetCtx.putImageData(targetData,0,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment