Skip to content

Instantly share code, notes, and snippets.

@nelix
Created November 26, 2012 21:54
Show Gist options
  • Select an option

  • Save nelix/4150892 to your computer and use it in GitHub Desktop.

Select an option

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?
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