From c64d21a119655e5a9b5704c30e3e530bb9cb99b5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 22 Nov 2022 16:57:15 +0100 Subject: [PATCH] fix placing of canvas img --- src/js/whiteboard.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/js/whiteboard.js b/src/js/whiteboard.js index e194215..372c9aa 100644 --- a/src/js/whiteboard.js +++ b/src/js/whiteboard.js @@ -904,7 +904,7 @@ const whiteboard = { if (draw == "1") { //draw image to canvas - _this.drawImgToCanvas(finalURL, width, height, left - _this.viewCoords.x, top - _this.viewCoords.y, rotationAngle); + _this.drawImgToCanvas(finalURL, width, height, left, top, rotationAngle); } else { //Add image to background _this.drawImgToBackground(finalURL, width, height, left, top, rotationAngle); @@ -1139,10 +1139,19 @@ const whiteboard = { img.onload = function () { rotationAngle = rotationAngle ? rotationAngle : 0; if (rotationAngle === 0) { - _this.ctx.drawImage(img, left + _this.viewCoords.x, top + _this.viewCoords.y, width, height); + _this.ctx.drawImage( + img, + left + _this.viewCoords.x, + top + _this.viewCoords.y, + width, + height + ); } else { _this.ctx.save(); - _this.ctx.translate(left + _this.viewCoords.x + width / 2, top + _this.viewCoords.y + height / 2); + _this.ctx.translate( + left + _this.viewCoords.x + width / 2, + top + _this.viewCoords.y + height / 2 + ); _this.ctx.rotate(rotationAngle); _this.ctx.drawImage(img, -(width / 2), -(height / 2), width, height); _this.ctx.restore();