Created
January 12, 2019 18:01
-
-
Save owencm/ecc4589e67abb22cca29ea2b565db8e6 to your computer and use it in GitHub Desktop.
Convert a blob to an image with JavaScript (e.g. to render blob to canvas)
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
const blobToImage = (blob) => { | |
return new Promise(resolve => { | |
const url = URL.createObjectURL(blob) | |
let img = new Image() | |
img.onload = () => { | |
URL.revokeObjectURL(url) | |
resolve(img) | |
} | |
img.src = url | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAA0lBMVEXBHDsMDQ0gICAsKyyUIzOYIjSbITSeIDWiIjaZITSVIjOnIzegIjUAAABJSUqdITR8e3sQEREADAtMTE1YWFjGGzwaGxslJSZzcnJmZWW6HTobIB8fLCsWFxcdICBdXFwlKywdLCsLIB6zHjiLIjEUIB9SKC8lICFHFh1fGiQ3Ki1CKS4vICJ