From 032d80dc3853512209b91b0c08eda28287937f8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 29 Mar 2019 17:23:27 +0100 Subject: [PATCH] Fix calcuation of canvas size The previous version failed if an image should be scaled to a square and the original is higher than wide. --- .../files/js/WoltLabSuite/Core/Image/Resizer.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/Resizer.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/Resizer.js index f427f6159e..1c06c48492 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/Resizer.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/Resizer.js @@ -174,14 +174,9 @@ define([ } // Keep image ratio - if (newWidth >= newHeight) { - canvas.width = newWidth; - canvas.height = newWidth * (image.height / image.width); - } - else { - canvas.width = newHeight * (image.width / image.height); - canvas.height = newHeight; - } + var ratio = Math.min(newWidth / image.width, newHeight / image.height); + canvas.width = Math.floor(image.width * ratio); + canvas.height = Math.floor(image.height * ratio); // Map to Pica's quality var resizeQuality = 1; -- 2.20.1