]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/image-utils.ts
move from trending routes to alg param
[github/Chocobozzz/PeerTube.git] / server / helpers / image-utils.ts
index fdf06e848b86a294fa662d23751c699b519260c1..3ebf073058bd1f85e00abc49d5a59748ed4c81a3 100644 (file)
@@ -1,5 +1,5 @@
-import { extname } from 'path'
 import { remove, rename } from 'fs-extra'
+import { extname } from 'path'
 import { convertWebPToJPG, processGIF } from './ffmpeg-utils'
 import { logger } from './logger'
 
@@ -13,17 +13,31 @@ async function processImage (
 ) {
   const extension = extname(path)
 
+  if (path === destination) {
+    throw new Error('Jimp/FFmpeg needs an input path different that the output path.')
+  }
+
+  logger.debug('Processing image %s to %s.', path, destination)
+
   // Use FFmpeg to process GIF
   if (extension === '.gif') {
-    return processGIF(path, destination, newSize, keepOriginal)
+    await processGIF(path, destination, newSize)
+  } else {
+    await jimpProcessor(path, destination, newSize)
   }
 
-  if (path === destination) {
-    throw new Error('Jimp needs an input path different that the output path.')
-  }
+  if (keepOriginal !== true) await remove(path)
+}
 
-  logger.debug('Processing image %s to %s.', path, destination)
+// ---------------------------------------------------------------------------
 
+export {
+  processImage
+}
+
+// ---------------------------------------------------------------------------
+
+async function jimpProcessor (path: string, destination: string, newSize: { width: number, height: number }) {
   let jimpInstance: any
 
   try {
@@ -44,12 +58,4 @@ async function processImage (
     .resize(newSize.width, newSize.height)
     .quality(80)
     .writeAsync(destination)
-
-  if (keepOriginal !== true) await remove(path)
-}
-
-// ---------------------------------------------------------------------------
-
-export {
-  processImage
 }