Skip to content

Instantly share code, notes, and snippets.

@Vbitz

Vbitz/test.js Secret

Created December 6, 2013 03:04
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 Vbitz/64f4874e1fd6b1e2c398 to your computer and use it in GitHub Desktop.
Save Vbitz/64f4874e1fd6b1e2c398 to your computer and use it in GitHub Desktop.
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