Last active
April 3, 2017 17:37
-
-
Save rlemon/ee2e168db72f85dc3cbe0e5531281be1 to your computer and use it in GitHub Desktop.
async load image for js
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
async function loadImage(url) { | |
const res = await fetch(url, { mode: 'cors' }); | |
const buff = await res.arrayBuffer(); | |
const img = new Image(); | |
const data = btoa([...new Uint8Array(buff)].map(c=>String.fromCharCode(c)).join('')); | |
img.src = `data:image/jpeg;base64,${data}`; | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment