Skip to content

Commit 9de18b4

Browse files
committed
Better conversion to square thumbnail
1 parent 449f01e commit 9de18b4

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

server/core/helpers/image-utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ async function autoResize (options: {
117117
}) {
118118
const { sharpInstance, metadata, newSize, destination } = options
119119

120-
// Portrait mode targeting a landscape, apply some effect on the image
121-
const sourceIsPortrait = metadata.width <= metadata.height
120+
// Portrait/square input to landscape target
121+
const sourceIsPortraitOrSquare = metadata.width <= metadata.height
122122
const destIsPortraitOrSquare = newSize.width <= newSize.height
123123

124-
if (sourceIsPortrait && !destIsPortraitOrSquare) {
124+
// Portrait source to landscape destination
125+
// Or portrait source to landscape destination
126+
if (
127+
(sourceIsPortraitOrSquare && !destIsPortraitOrSquare) ||
128+
(!sourceIsPortraitOrSquare && destIsPortraitOrSquare)
129+
) {
125130
const foregroundImage = sharpInstance.clone()
126131
.resize(newSize.width, newSize.height, { fit: 'inside' })
127132

0 commit comments

Comments
 (0)