node.js使用sharp报错,没用过sharp不知道有没有写错,来人帮忙看一下代码有没有问题
const fs = require('fs')
const sharp = require('sharp')
async function splitMultiPageImage(inputPath,outputPathTemplate){
const image = sharp(inputPath)
const pages = await image.metadata().then(metadata => metadata.pages);
for (let i = 0 ; i < pages ; i++){
const pageStream = await image.clone().extractPage(i).toBuffer();
const outputPath = outputPathTemplate.replace('%d',i + 1) + '.jpg';
await sharp(pageStream)
.jpeg()
.toFile(outputPath);
}
}
splitMultiPageImage('./test.tif','./output/page-%d.jpg')
.then(() => console.log('图片拆分完成'))
.catch(err => console.error('图片拆分过程中出现问题',err))