Created
October 27, 2015 14:13
-
-
Save gartenfeld/95ab367dbe8fee3925aa to your computer and use it in GitHub Desktop.
Load an image and convert it to a string.
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
| var xhr = new XMLHttpRequest(); | |
| xhr.responseType = 'arraybuffer'; | |
| xhr.onload = function() { | |
| if (this.status == 200) { | |
| var buffer = new Uint8Array(this.response); | |
| var i = buffer.length; | |
| var binary = new Array(i); | |
| while (i--) { | |
| binary[i] = String.fromCharCode(buffer[i]); | |
| } | |
| var base64 = window.btoa(binary.join('')); | |
| } | |
| }; | |
| xhr.open('GET', URL, true); | |
| xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment