Skip to content

Instantly share code, notes, and snippets.

@gabrielstuff
Created March 7, 2014 10:26
Show Gist options
  • Save gabrielstuff/9409101 to your computer and use it in GitHub Desktop.
Save gabrielstuff/9409101 to your computer and use it in GitHub Desktop.
Canvas to webkit url without crashing your browser see references : https://code.google.com/p/chromium/issues/detail?id=69227
function getCanvasURL(canvas){
var parts = canvas.toDataURL().match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/);
//assume base64 encoding
var binStr = atob(parts[3]);
//convert to binary in ArrayBuffer
var buf = new ArrayBuffer(binStr.length);
var view = new Uint8Array(buf);
for (var i = 0; i < view.length; i++)
view[i] = binStr.charCodeAt(i);
var blob = new Blob([view], {
'type': parts[1]
});
return webkitURL.createObjectURL(blob);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment