aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/image-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-10 14:54:11 +0200
committerChocobozzz <me@florianbigard.com>2020-07-10 14:54:11 +0200
commit187822421489ae811d118d15aa2d8361183250c2 (patch)
treebe429819c049384819fde76df33d46f4886d8ad1 /server/helpers/image-utils.ts
parent72493e44e9b455a04c4f093ed6c6ffa300b98d8b (diff)
downloadPeerTube-187822421489ae811d118d15aa2d8361183250c2.tar.gz
PeerTube-187822421489ae811d118d15aa2d8361183250c2.tar.zst
PeerTube-187822421489ae811d118d15aa2d8361183250c2.zip
Handle webp images from youtube-dl
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r--server/helpers/image-utils.ts21
1 files changed, 16 insertions, 5 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index b1c7d3d47..f2f6a004f 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,6 +1,7 @@
1import 'multer' 1import { remove, rename } from 'fs-extra'
2import { readFile, remove } from 'fs-extra' 2import { convertWebPToJPG } from './ffmpeg-utils'
3import { logger } from './logger' 3import { logger } from './logger'
4
4const Jimp = require('jimp') 5const Jimp = require('jimp')
5 6
6async function processImage ( 7async function processImage (
@@ -15,9 +16,19 @@ async function processImage (
15 16
16 logger.debug('Processing image %s to %s.', path, destination) 17 logger.debug('Processing image %s to %s.', path, destination)
17 18
18 // Avoid sharp cache 19 let jimpInstance: any
19 const buf = await readFile(path) 20
20 const jimpInstance = await Jimp.read(buf) 21 try {
22 jimpInstance = await Jimp.read(path)
23 } catch (err) {
24 logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', { err })
25
26 const newName = path + '.jpg'
27 await convertWebPToJPG(path, newName)
28 await rename(newName, path)
29
30 jimpInstance = await Jimp.read(path)
31 }
21 32
22 await remove(destination) 33 await remove(destination)
23 34