Skip to content

Instantly share code, notes, and snippets.

@devongovett
Created March 27, 2012 18:11
Show Gist options
  • Save devongovett/2218587 to your computer and use it in GitHub Desktop.
Save devongovett/2218587 to your computer and use it in GitHub Desktop.
get a blob from a canvas
function getBlob(canvas) {
var data = atob(canvas.toDataURL().replace('data:image/png;base64,', '')),
bytes = new Uint8Array(data.length);
for (var i = 0, len = data.length; i < len; i++) {
bytes[i] = data.charCodeAt(i) & 0xff;
}
var bb = new BlobBuilder();
bb.append(bytes.buffer);
return bb.getBlob('image/png');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment