📜  nodejs 将图像急剧更改为多种尺寸 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:52.688000             🧑  作者: Mango

代码示例1
// Sharp and FS module needed.
;(async function(){
    let imgBuffer = await sharp("./myimage.jpg").toBuffer()
    let thumbnail = await sharp(imgBuffer).resize(100, 100).toBuffer()
    let image = await sharp(imgBuffer).resize(1600, 900).toBuffer()
    fs.writeFile("./thumbnail.jpg", thumbnail, err => {
        if(err) console.log(err)
    })
    fs.writeFile("./image.jpg", thumbnail, err => {
      if(err) console.log(err)
    })
})