【发布时间】:2021-01-28 07:32:24
【问题描述】:
我在使用Sharp 方面需要帮助,我希望我的图片在上传时调整大小,但我似乎无法做到这一点。
router.post("/", upload.single("image"), async (req, res) => {
const { filename: image } = req.file;
await sharp(req.file.path)
.resize(300, 200)
.jpeg({ quality: 50 })
.toFile(path.resolve(req.file.destination, "resized", image));
fs.unlinkSync(req.file.path);
res.send("sent");
});
【问题讨论】:
-
this link 包含并实现了用于文件上传的sharp和multer,看看这个