jimp爬取网络图片到本地

// https://www.npmjs.com/package/jimp
const Jimp = require('jimp')
Jimp.read(`https://readfree.me/${id}`)
  .then(lenna => {
      const url = path.join(__dirname, `../public/${id}`)
      lenna
          .resize(256, Jimp.AUTO) // resize
          .quality(90) // set JPEG quality
          .write(url) // save
  })
  .catch(err => {
      data.thumbnail = 'default.jpg'
  })
posted @ 2021-10-08 10:17  wmui  阅读(72)  评论(0编辑  收藏  举报