diff --git a/src/drawer.js b/src/drawer.js index 661663d1..cc13cacb 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.canvas.width) { + bounds.width = this.canvas.width; + } + if (bounds.y < 0) { + bounds.height += bounds.y; + bounds.y = 0; + } + if (bounds.height > this.canvas.height) { + bounds.height = this.canvas.height; + } + this.context.drawImage( this.sketchCanvas, bounds.x,