Created
March 7, 2014 10:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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