From d1c656f678e254b1fc790c4fa38da9b919a77ce7 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 28 Apr 2024 11:45:57 -0400 Subject: [PATCH] Fix --- util/Canvas.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/util/Canvas.js b/util/Canvas.js index 296512a4..879c540f 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -277,26 +277,26 @@ module.exports = class CanvasUtil { static centerImagePart(img, boxWidth, boxHeight, boxX, boxY) { const imgAspectRatio = img.width / img.height; - const boxAspectRatio = boxWidth / boxHeight; - let drawWidth; + const boxAspectRatio = boxWidth / boxHeight; + let drawWidth; let drawHeight; - if (imgAspectRatio > boxAspectRatio) { - drawWidth = boxWidth; - drawHeight = drawWidth / imgAspectRatio; - if (drawHeight > boxHeight) { - drawHeight = boxHeight; - drawWidth = drawHeight * imgAspectRatio; - } - } else { - drawHeight = boxHeight; - drawWidth = drawHeight * imgAspectRatio; - if (drawWidth > boxWidth) { - drawWidth = boxWidth; - drawHeight = drawWidth / imgAspectRatio; - } - } - const drawX = boxX + ((boxWidth - drawWidth) / 2); - const drawY = boxY + ((boxHeight - drawHeight) / 2); + if (imgAspectRatio > boxAspectRatio) { + drawWidth = boxWidth; + drawHeight = drawWidth / imgAspectRatio; + if (drawHeight > boxHeight) { + drawHeight = boxHeight; + drawWidth = drawHeight * imgAspectRatio; + } + } else { + drawHeight = boxHeight; + drawWidth = drawHeight * imgAspectRatio; + if (drawWidth > boxWidth) { + drawWidth = boxWidth; + drawHeight = drawWidth / imgAspectRatio; + } + } + const drawX = boxX + ((boxWidth - drawWidth) / 2); + const drawY = boxY + ((boxHeight - drawHeight) / 2); return { x: drawX, y: drawY, width: drawWidth, height: drawHeight }; } };