From 67cf5e83b7177cc14551f41ed180580037dec7fc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 8 Dec 2020 09:48:32 -0500 Subject: [PATCH] fix: changes to thumb resizing logic - Resized thumb no longer skews aspect ratio - Thumbs resized down to maximum thumb size by WIDTH only - image.checkDimensions() now returns dimensions --- src/controllers/uploads.js | 14 ++++++++------ src/image.js | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index 8055c02b98..266c623548 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -120,12 +120,14 @@ uploadsController.uploadThumb = async function (req, res) { throw new Error('[[error:invalid-file]]'); } await image.isFileTypeAllowed(uploadedFile.path); - await image.checkDimensions(uploadedFile.path); - await image.resizeImage({ - path: uploadedFile.path, - width: meta.config.topicThumbSize, - height: meta.config.topicThumbSize, - }); + const dimensions = await image.checkDimensions(uploadedFile.path); + + if (dimensions.width > parseInt(meta.config.topicThumbSize, 10)) { + await image.resizeImage({ + path: uploadedFile.path, + width: meta.config.topicThumbSize, + }); + } if (plugins.hooks.hasListeners('filter:uploadImage')) { return await plugins.hooks.fire('filter:uploadImage', { image: uploadedFile, diff --git a/src/image.js b/src/image.js index a6b5310adb..ec73a0bc08 100644 --- a/src/image.js +++ b/src/image.js @@ -105,6 +105,8 @@ image.checkDimensions = async function (path) { if (result.width > meta.config.rejectImageWidth || result.height > meta.config.rejectImageHeight) { throw new Error('[[error:invalid-image-dimensions]]'); } + + return result; }; image.convertImageToBase64 = async function (path) {