]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/image-utils.ts
Fix live update error
[github/Chocobozzz/PeerTube.git] / server / helpers / image-utils.ts
index 206cfa5bc7198824defcd23ade2e1b8b535c224e..b174ae4369208e8d10eeec1816425c6d4ed7fb63 100644 (file)
@@ -1,9 +1,9 @@
 import { copy, readFile, remove, rename } from 'fs-extra'
 import Jimp, { read } from 'jimp'
-import { getLowercaseExtension } from './core-utils'
+import { getLowercaseExtension } from '@shared/core-utils'
+import { buildUUID } from '@shared/extra-utils'
 import { convertWebPToJPG, processGIF } from './ffmpeg-utils'
 import { logger } from './logger'
-import { buildUUID } from './uuid'
 
 function generateImageFilename (extension = '.jpg') {
   return buildUUID() + extension
@@ -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) {