Skip to content

Instantly share code, notes, and snippets.

@navdeepsingh
Forked from rayinla/refactored-gpix.js
Created July 24, 2018 04:40
Show Gist options
  • Save navdeepsingh/c95e22e2bc0cb8c514833fa5b8c7c169 to your computer and use it in GitHub Desktop.
Save navdeepsingh/c95e22e2bc0cb8c514833fa5b8c7c169 to your computer and use it in GitHub Desktop.
let $photoInput = document.getElementById("input");
let image = new Image();
let $editor = document.getElementById("editor");
let $editorCtx = $editor.getContext("2d");
function opacitor(op) {
let imgData = $editorCtx.getImageData(0, 0, $editor.width, $editor.height);
for (let x = 0; x < image.width; x++) {
for (let y = 0; y < image.height; y++) {
let index = (x + y * image.width) * 4;
imgData.data[index + 3] = op;
}
}
$editorCtx.putImageData(imgData, 0, 0);
}
$photoInput.addEventListener("change", e => {
let file = e.target.files[0];
createImageBitmap(file).then(bitmap => {
$editor.width = bitmap.width;
$editor.height = bitmap.height;
$editorCtx.drawImage(bitmap, 0, 0);
opacitor(257);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment