From 83c51a10429e371a2760fed854e2fb89be95ae4c Mon Sep 17 00:00:00 2001 From: Debugreality Date: Thu, 23 Nov 2017 07:12:54 +1100 Subject: [PATCH] Update imageupload.js --- public/javascripts/imageupload.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/public/javascripts/imageupload.js b/public/javascripts/imageupload.js index c3c1453..0d6729c 100644 --- a/public/javascripts/imageupload.js +++ b/public/javascripts/imageupload.js @@ -30,18 +30,11 @@ angular.module('imageupload', []) var height = origImage.height; var width = origImage.width; - // calculate the width and height, constraining the proportions - if (width > height) { - if (width > maxWidth) { - height = Math.round(height *= maxWidth / width); - width = maxWidth; - } - } else { - if (height > maxHeight) { - width = Math.round(width *= maxHeight / height); - height = maxHeight; - } - } + var scale = 1; + if(width > maxWidth || height > maxHeight) scale = Math.min(maxWidth / width, maxHeight / height); + + height = height * scale; + width = width * scale; canvas.width = width; canvas.height = height;