-
-
Save Vbitz/64f4874e1fd6b1e2c398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var img = new Image(); | |
var readerCanvas = document.createElement("canvas"); | |
var ctx = readerCanvas.getContext("2d"); | |
img.onload = function () { | |
ctx.width = this.width; | |
ctx.height = this.height; | |
ctx.drawImage(this, 0, 0); | |
var imgd = ctx.getImageData(0, 0, this.width, this.height); | |
var pix = imgd.data; | |
var i = 0; | |
pixelData = []; | |
for (var y = 0; y < this.height; y++) { | |
pixelData[y] = []; | |
for (var x = 0; x < this.width; x++) { | |
pixelData[y][x] = { // some of these values are off by 1 | |
r: pix[i + 0], | |
g: pix[i + 1], | |
b: pix[i + 2], | |
a: pix[i + 3], | |
}; | |
i += 4; | |
} | |
} | |
}; | |
img.src = dataURL; // a data url from the local system |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment