From d75f68227e511e419b0c5b7275888a472896485f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 27 Oct 2020 11:56:41 -0400 Subject: [PATCH] fix firefox compatibility bug --- src/human.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/human.js b/src/human.js index b862955e..4730b5ea 100644 --- a/src/human.js +++ b/src/human.js @@ -139,8 +139,9 @@ class Human { let targetHeight = originalHeight; if (this.config.filter.height > 0) targetHeight = this.config.filter.height; else if (this.config.filter.width > 0) targetHeight = originalHeight * (this.config.filter.width / originalWidth); - - const offscreenCanvas = new OffscreenCanvas(targetWidth, targetHeight); + const offscreenCanvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement('canvas'); + offscreenCanvas.width = targetWidth; + offscreenCanvas.height = targetHeight; const ctx = offscreenCanvas.getContext('2d'); if (input instanceof ImageData) ctx.putImageData(input, 0, 0); else ctx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, offscreenCanvas.width, offscreenCanvas.height);