From c24e8ceedfd59d79cf4a61926068b16edf2c964c Mon Sep 17 00:00:00 2001 From: A Date: Fri, 23 Sep 2016 15:57:35 -0400 Subject: [PATCH] Fix IndexSizeError on IE and Edge #1033 Internet Explorer and Microsoft Edge throw IndexSizeError when you call context.drawImage with negative x or y or width or height greater than the canvas width or height respectively. --- src/drawer.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/drawer.js b/src/drawer.js index 661663d1..77a4c8a1 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -423,6 +423,24 @@ $.Drawer.prototype = { this.context.globalCompositeOperation = compositeOperation; } if (bounds) { + // Internet Explorer and Microsoft Edge throw IndexSizeError + // when you call context.drawImage with negative x or y + // or width or height greater than the canvas width or height respectively + if (bounds.x < 0) { + bounds.width += bounds.x; + bounds.x = 0; + } + if (bounds.width > this.sketchCanvas.width) { + bounds.width = this.sketchCanvas.width; + } + if (bounds.y < 0) { + bounds.height += bounds.y; + bounds.y = 0; + } + if (bounds.height > this.sketchCanvas.height) { + bounds.height = this.sketchCanvas.height; + } + this.context.drawImage( this.sketchCanvas, bounds.x,