Created
November 26, 2012 21:54
-
-
Save nelix/4150892 to your computer and use it in GitHub Desktop.
Can anyone think of a faster or more correct way to convert a canvas object to a blob?
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 dataURIToBlob(dataURI) { | |
| var parts = dataURI.split(','); | |
| var binary = atob(parts[1]); | |
| var type = parts[0]; | |
| var array = []; | |
| for(var i = 0; i < binary.length; i++) { | |
| array.push(binary.charCodeAt(i)); | |
| } | |
| return new Blob([new Uint8Array(array).buffer], {type: type}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment