From 0f99d8e10bf384623dbc3dc598b805ac5ea08d92 Mon Sep 17 00:00:00 2001 From: spaciecat <5057054+spaciecat@users.noreply.github.com> Date: Sat, 14 Sep 2019 23:11:31 +1000 Subject: [PATCH] add createImageBitmap polyfill the changes i made to the image pipeline required stuff that needs a polyfill, so here it is! --- index.html | 1 + scripts/lib/createImageBitmap.js | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 scripts/lib/createImageBitmap.js diff --git a/index.html b/index.html index 8891e02..73a95f0 100644 --- a/index.html +++ b/index.html @@ -216,6 +216,7 @@ + diff --git a/scripts/lib/createImageBitmap.js b/scripts/lib/createImageBitmap.js new file mode 100644 index 0000000..f4173d3 --- /dev/null +++ b/scripts/lib/createImageBitmap.js @@ -0,0 +1,33 @@ +/* +* Safari and Edge polyfill for createImageBitmap +* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap +* +* Support source image types Blob and ImageData. +* +* From: https://dev.to/nektro/createimagebitmap-polyfill-for-safari-and-edge-228 +* Updated by Yoan Tournade +*/ +if (!('createImageBitmap' in window)) { + window.createImageBitmap = async function (data) { + return new Promise((resolve,reject) => { + let dataURL; + if (data instanceof Blob) { + dataURL = URL.createObjectURL(data); + } else if (data instanceof ImageData) { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + canvas.width = data.width; + canvas.height = data.height; + ctx.putImageData(data,0,0); + dataURL = canvas.toDataURL(); + } else { + throw new Error('createImageBitmap does not handle the provided image source type'); + } + const img = document.createElement('img'); + img.addEventListener('load',function () { + resolve(this); + }); + img.src = dataURL; + }); + }; +} \ No newline at end of file