Created
December 16, 2015 21:44
-
-
Save aermolaev/a96ba40cd68fe357195f to your computer and use it in GitHub Desktop.
This file contains 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 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 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
Its loosing image orientation(making vertical image to horizontal) for portrait images taken on ios devices, how to fix this?