Skip to content

Instantly share code, notes, and snippets.

@sr3d sr3d/x1.js
Created Aug 22, 2010

Embed
What would you like to do?
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
You can’t perform that action at this time.