+ // Use FFmpeg to process GIF
+ if (extension === '.gif') {
+ await processGIF(path, destination, newSize)
+ } else {
+ await jimpProcessor(path, destination, newSize, extension)
+ }
+
+ if (keepOriginal !== true) await remove(path)
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ generateImageFilename,
+ processImage
+}
+
+// ---------------------------------------------------------------------------
+
+async function jimpProcessor (path: string, destination: string, newSize: { width: number, height: number }, inputExt: string) {
+ let jimpInstance: Jimp
+ const inputBuffer = await readFile(path)
+
+ try {
+ jimpInstance = await Jimp.read(inputBuffer)
+ } 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)
+ }