2 import * as sharp from 'sharp'
3 import { move, remove } from 'fs-extra'
5 async function processImage (
6 physicalFile: { path: string },
8 newSize: { width: number, height: number }
10 if (physicalFile.path === destination) {
11 throw new Error('Sharp needs an input path different that the output path.')
14 const sharpInstance = sharp(physicalFile.path)
15 const metadata = await sharpInstance.metadata()
18 if (metadata.width === newSize.width && metadata.height === newSize.height) {
19 await move(physicalFile.path, destination, { overwrite: true })
23 await remove(destination)
26 .resize(newSize.width, newSize.height)
29 await remove(physicalFile.path)
32 // ---------------------------------------------------------------------------