Skip to content

Instantly share code, notes, and snippets.

@Zyzle
Last active September 23, 2022 20:40
Show Gist options
  • Save Zyzle/1cf16675d7224ef90b0ef1639c7783a9 to your computer and use it in GitHub Desktop.
Save Zyzle/1cf16675d7224ef90b0ef1639c7783a9 to your computer and use it in GitHub Desktop.
Correcting image-colours to work with browsers that don't support 2d context in OffscreenCanvas
// Around line 127
createImageBitmap(file).then((ibm) => {
let ctx;
if (typeof OffscreenCanvasRenderingContext === "function"){
const canvas = new OffscreenCanvas(ibm.width, ibm.height);
ctx = canvas.getContext("2d");
}
else {
const canvas = document.createElement("canvas");
ctx = canvas.getContext("2d");
ctx.canvas.height = ibm.height;
ctx.canvas.width = ibm.width;
}
ctx.drawImage(ibm, 0, 0);
// rest of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment