Backdrop filter compatibility for Firefox and Safari

This commit is contained in:
Germain Souquet 2021-06-25 09:20:03 +01:00
parent 27ee7c5836
commit 652ad3617d
9 changed files with 55 additions and 14 deletions

24
src/utils/drawable.ts Normal file
View file

@ -0,0 +1,24 @@
/**
* Fetch an image using the best available method based on browser compatibility
* @param url the URL of the image to fetch
* @returns a canvas drawable object
*/
export async function getDrawable(url: string): Promise<CanvasImageSource> {
if ('createImageBitmap' in window) {
const response = await fetch(url);
const blob = await response.blob();
return await createImageBitmap(blob);
} else {
return new Promise((resolve, reject) => {
const img = document.createElement("img");
img.crossOrigin = "anonymous";
img.onload = function() {
resolve(img);
}
img.onerror = function(e) {
reject(e);
}
img.src = url;
});
}
}