2 import { readFile, remove } from 'fs-extra'
3 import { logger } from './logger'
4 const Jimp = require('jimp')
6 async function processImage (
9 newSize: { width: number, height: number },
12 if (path === destination) {
13 throw new Error('Jimp needs an input path different that the output path.')
16 logger.debug('Processing image %s to %s.', path, destination)
19 const buf = await readFile(path)
20 const jimpInstance = await Jimp.read(buf)
22 await remove(destination)
25 .resize(newSize.width, newSize.height)
27 .writeAsync(destination)
29 if (keepOriginal !== true) await remove(path)
32 // ---------------------------------------------------------------------------