Prefer cover instead of contain for images

pull/4548/head
Chocobozzz 2021-11-16 16:11:10 +01:00
parent 7196a70b28
commit 9c7cf0072f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 6 additions and 3 deletions

View File

@ -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) {