Skip to content

Instantly share code, notes, and snippets.

@nektro
Created November 7, 2017 01:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nektro/84654b5183ddd1ccb7489607239c982d to your computer and use it in GitHub Desktop.
Save nektro/84654b5183ddd1ccb7489607239c982d to your computer and use it in GitHub Desktop.
Edge and Safari Polyfill for createImageBitmap
/* Safari and Edge polyfill for createImageBitmap
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap
*/
if (!('createImageBitmap' in window)) {
window.createImageBitmap = async function(blob) {
return new Promise((resolve,reject) => {
let img = document.createElement('img');
img.addEventListener('load', function() {
resolve(this);
});
img.src = URL.createObjectURL(blob);
});
}
}
@MonsieurV
Copy link

Here an updated version with ImageData support: https://gist.github.com/MonsieurV/fb640c29084c171b4444184858a91bc7

Thx for the snippet, was of great help :) 👍

@pseudosavant
Copy link

I took it a bit further and added support for CanvasImageSource sources. Thanks! https://gist.github.com/pseudosavant/a6d970b945ae85ef4dbc43200da94faf

@jimmywarting
Copy link

I took it a bit further

And I took it a bit smaller

self.createImageBitmap=self.createImageBitmap||(b,i=new Image)=>i.decode(i.src=URL.createObjectURL(b)).then(_=>i)

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