The variable names canvasWidth and Height are confusing because they are different than canvas.width and canvas.height. Could you use containerWidth and containerHeight instead?  (I'm assuming that these arguments hold the size of the onscreen region that the image editor is operating within).