Skip to content

Instantly share code, notes, and snippets.

@sr3d
Created August 22, 2010 22:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sr3d/544352 to your computer and use it in GitHub Desktop.
Save sr3d/544352 to your computer and use it in GitHub Desktop.
var x1 = function( z, m ) { // image url, callback
var o = new Image();
o.onload = function() {
var s = "",
c = d.createElement("canvas"),
t = c.getContext("2d"),
w = o.width,
h = o.height;
c.width = c.style.width = w;
c.height = c.style.height = h;
var chunkSize = 8192;
var chunksCount = Math.ceil( h / chunkSize );
var temp = []
for( var j = 0; j < chunksCount; j++ ) {
var from = j * chunkSize,
to = Math.min( chunkSize, h - from );
t.drawImage(o, 0, -from); // shift the image up by the chunksize
var b = t.getImageData( 0, 0, 1, Math.min( chunkSize, h - from ) ).data;
for(var i= 0; i < b.length; i += 4) {
if( b[i] > 0 )
s += String.fromCharCode(b[i]);
}
}
m(s);
}
o.src = z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment