使用锐利调整流中图像的大小

时间:2019-12-06 04:54:42

标签: javascript node.js sharp

如何调整流中图像的大小?使用犀利的图书馆? https://github.com/lovell/sharp

代码


exports.getVehicleImageProfile = function (req, res) {

    gfs.findOne({ filename: req.params.filename }, function (err, file) {
        if (file) {
            const readstream = gfs.createReadStream(file.filename);
            readstream.on('data', (chunk) => {

            }).pipe(res)

        }
    });

}

}```

1 个答案:

答案 0 :(得分:0)

根据documentation,您可以将流直接传送到 sharp 以调整图像大小:

const s = sharp().resize(200, 200);
readstream.pipe(s).pipe(...);
相关问题