Skip to content

Instantly share code, notes, and snippets.

@owencm
Created January 12, 2019 18:01
Show Gist options
  • Save owencm/ecc4589e67abb22cca29ea2b565db8e6 to your computer and use it in GitHub Desktop.
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)
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
})
}
@rafaelvidalwba
Copy link

iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAA0lBMVEXBHDsMDQ0gICAsKyyUIzOYIjSbITSeIDWiIjaZITSVIjOnIzegIjUAAABJSUqdITR8e3sQEREADAtMTE1YWFjGGzwaGxslJSZzcnJmZWW6HTobIB8fLCsWFxcdICBdXFwlKywdLCsLIB6zHjiLIjEUIB9SKC8lICFHFh1fGiQ3Ki1CKS4vICJ

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