X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fimage-utils.ts;h=5f254a7aaf04594de6af26331ef667b8c0b23eef;hb=6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156;hp=b1c7d3d476c549c395dbb8ff8207fc469f21d52b;hpb=e6dfa58689e88633db8304a8541a75edd893c645;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index b1c7d3d47..5f254a7aa 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts @@ -1,6 +1,7 @@ -import 'multer' -import { readFile, remove } from 'fs-extra' +import { remove, rename } from 'fs-extra' +import { convertWebPToJPG } from './ffmpeg-utils' import { logger } from './logger' + const Jimp = require('jimp') async function processImage ( @@ -15,9 +16,19 @@ async function processImage ( logger.debug('Processing image %s to %s.', path, destination) - // Avoid sharp cache - const buf = await readFile(path) - const jimpInstance = await Jimp.read(buf) + let jimpInstance: any + + try { + jimpInstance = await Jimp.read(path) + } catch (err) { + logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) + + const newName = path + '.jpg' + await convertWebPToJPG(path, newName) + await rename(newName, path) + + jimpInstance = await Jimp.read(path) + } await remove(destination)