2 import * as sharp from 'sharp'
3 import { readFile, remove } from 'fs-extra'
4 import { logger } from './logger'
6 async function processImage (
7 physicalFile: { path: string },
9 newSize: { width: number, height: number }
11 if (physicalFile.path === destination) {
12 throw new Error('Sharp needs an input path different that the output path.')
15 logger.debug('Processing image %s to %s.', physicalFile.path, destination)
18 const buf = await readFile(physicalFile.path)
19 const sharpInstance = sharp(buf)
21 await remove(destination)
24 .resize(newSize.width, newSize.height)
27 await remove(physicalFile.path)
30 // ---------------------------------------------------------------------------