Skip to content

Instantly share code, notes, and snippets.

@aermolaev
Created December 16, 2015 21:44
Show Gist options
  • Save aermolaev/a96ba40cd68fe357195f to your computer and use it in GitHub Desktop.
Save aermolaev/a96ba40cd68fe357195f to your computer and use it in GitHub Desktop.
function dataURLToBlob(dataURL) {
var BASE64_MARKER = ';base64,';
if (dataURL.indexOf(BASE64_MARKER) == -1) {
var parts = dataURL.split(',');
var contentType = parts[0].split(':')[1];
var raw = decodeURIComponent(parts[1]);
return new Blob([raw], {type: contentType});
}
var parts = dataURL.split(BASE64_MARKER);
var contentType = parts[0].split(':')[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {type: contentType});
}
@Swapnilchavan18
Copy link

Its loosing image orientation(making vertical image to horizontal) for portrait images taken on ios devices, how to fix this?

@SagePtr
Copy link

SagePtr commented Apr 22, 2019

@Swapnilchavan18 no, it does not. It just converts data:uri object to blob, not knowing what's inside. Probably your data:uri was generated incorrectly, or blob is processed incorrectly later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment