From cbdf997ccf1b498a63ea8a384733271974f57114 Mon Sep 17 00:00:00 2001 From: javl Date: Fri, 11 Jun 2021 13:42:07 +0200 Subject: [PATCH] feat: add option to flip image, fixed #45 --- index.html | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index eff79b7..f6787de 100644 --- a/index.html +++ b/index.html @@ -318,6 +318,16 @@ + +
+
+
+ + + + +
+
Note: centering the image only works when using a canvas larger than the original image. @@ -661,6 +671,8 @@ preserveRatio: true, centerHorizontally: false, centerVertically: false, + flipHorizontally: false, + flipVertically: false, backgroundColor: "white", scale: "1", drawMode: "horizontal", @@ -766,10 +778,6 @@ var ctx = canvas.getContext("2d"); image.ctx = ctx; - // Make sure we're using the right canvas size - //canvas.width = settings["screenWidth"]; - //canvas.height = settings["screenHeight"]; - // Invert background if needed if (settings["backgroundColor"] == "transparent") { ctx.fillStyle = "rgba(0,0,0,0.0)"; @@ -830,6 +838,20 @@ invert(canvas, ctx); } } + + // Flip image if needed + if (settings["flipHorizontally"]) { + ctx.save(); + ctx.scale(-1, 1); + ctx.drawImage(canvas, -canvas.width, 0); + ctx.restore(); + } + if (settings["flipVertically"]) { + ctx.save(); + ctx.scale(1, -1); + ctx.drawImage(canvas, 0, -canvas.height); + ctx.restore(); + } } // Handle inserting an image by pasting code