From: Tim Düsterhus Date: Fri, 29 Mar 2019 16:23:27 +0000 (+0100) Subject: Fix calcuation of canvas size X-Git-Tag: 5.2.0_Alpha_1~124^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=032d80dc3853512209b91b0c08eda28287937f8b;p=GitHub%2FWoltLab%2FWCF.git 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. --- 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;