Skip to content

Instantly share code, notes, and snippets.

@maheshbabu
Forked from owencm/blob-to-image.js
Created April 8, 2020 14:36
Show Gist options
  • Save maheshbabu/7c7717cdc40049ae8b6bfba3cb0ffa95 to your computer and use it in GitHub Desktop.
Save maheshbabu/7c7717cdc40049ae8b6bfba3cb0ffa95 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
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment