From 9c7cf0072ffbfff7e1d3276af9123d9c5a3a0aa6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Nov 2021 16:11:10 +0100 Subject: [PATCH] Prefer cover instead of contain for images --- server/helpers/image-utils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index 206cfa5bc..4305584d5 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts @@ -76,8 +76,11 @@ async function autoResize (options: { }) { const { sourceImage, newSize, destination } = options - // Portrait mode, special handling - if (sourceImage.getWidth() < sourceImage.getHeight()) { + // Portrait mode targetting a landscape, apply some effect on the image + const sourceIsPortrait = sourceImage.getWidth() < sourceImage.getHeight() + const destIsPortraitOrSquare = newSize.width <= newSize.height + + if (sourceIsPortrait && !destIsPortraitOrSquare) { const baseImage = sourceImage.cloneQuiet().cover(newSize.width, newSize.height) .color([ { apply: 'shade', params: [ 50 ] } ]) @@ -86,7 +89,7 @@ async function autoResize (options: { return write(baseImage.blit(topImage, 0, 0), destination) } - return write(sourceImage.contain(newSize.width, newSize.height), destination) + return write(sourceImage.cover(newSize.width, newSize.height), destination) } function write (image: Jimp, destination: string) {