1 import { remove, rename } from 'fs-extra'
2 import { convertWebPToJPG } from './ffmpeg-utils'
3 import { logger } from './logger'
5 const Jimp = require('jimp')
7 async function processImage (
10 newSize: { width: number, height: number },
13 if (path === destination) {
14 throw new Error('Jimp needs an input path different that the output path.')
17 logger.debug('Processing image %s to %s.', path, destination)
22 jimpInstance = await Jimp.read(path)
24 logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err })
26 const newName = path + '.jpg'
27 await convertWebPToJPG(path, newName)
28 await rename(newName, path)
30 jimpInstance = await Jimp.read(path)
33 await remove(destination)
36 .resize(newSize.width, newSize.height)
38 .writeAsync(destination)
40 if (keepOriginal !== true) await remove(path)
43 // ---------------------------------------------------------------------------