From 536657e0e848d6ffe37cf34b83cec89910bdc529 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Thu, 30 Dec 2021 21:53:34 +1030 Subject: [PATCH] Calculate scalefactor automatically --- web/data/editor.html | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/web/data/editor.html b/web/data/editor.html index cd8c4f2..efab6cc 100644 --- a/web/data/editor.html +++ b/web/data/editor.html @@ -94,7 +94,7 @@ function editor() { }); fabric.Image.fromURL('/rest/image/'+id, function(oImg) { - // TODO set scalefactor appropriately + self.scaleFactor = scalefactor(oImg.width, oImg.height); canvas.setDimensions({width: oImg.width, height: oImg.height}); oImg.selectable = false; canvas.add(oImg); @@ -173,6 +173,22 @@ function editor() { } } + +function scalefactor(width, height) { + max_width = 800; + max_height = 600; + + if (width <= max_width && height <= max_height) { + return 1.0; + } + + factor = max_width/width; + if (height*factor <= max_height) { + return factor; + } + + return height/max_height; +}