diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-10 15:23:31 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-07-10 15:23:31 +0200 |
commit | 17aa80ed016bafa3ccb071af3f86054033823284 (patch) | |
tree | 8f323ba78a0bc6554489ea7a52518ba773ab28a1 /server/helpers/image-utils.ts | |
parent | e3489df98e0d31caa890f2d50d0e531c33a06d86 (diff) | |
parent | 1dee8d68cb89ea98610ab61291e640991d3506e6 (diff) | |
download | PeerTube-17aa80ed016bafa3ccb071af3f86054033823284.tar.gz PeerTube-17aa80ed016bafa3ccb071af3f86054033823284.tar.zst PeerTube-17aa80ed016bafa3ccb071af3f86054033823284.zip |
Merge branch 'release/2.3.0' into develop
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 21 |
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 @@ | |||
1 | import 'multer' | 1 | import { remove, rename } from 'fs-extra' |
2 | import { readFile, remove } from 'fs-extra' | 2 | import { convertWebPToJPG } from './ffmpeg-utils' |
3 | import { logger } from './logger' | 3 | import { logger } from './logger' |
4 | |||
4 | const Jimp = require('jimp') | 5 | const Jimp = require('jimp') |
5 | 6 | ||
6 | async function processImage ( | 7 | async 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 | ||