I cannot resize image. I am using multer for getting files, but how can I resize this image? I tried imagestick but fs didn't save them.
router.post('/uploadAvatar',
multer({
dest: './public/uploads/images/avatars',
rename: function (fieldname, filename) {
return 'avatar'+Date.now();
}
}), function(req, res) {
// resize image
res.json(newPath);
});
I like Sharp module to play with images in Node.js:
router.post('/uploadAvatar',
multer({
dest: './public/uploads/images/avatars',
rename: function (fieldname, filename) {
return 'avatar'+Date.now();
}
}), function(req, res) {
// resize image
sharp(newPath).resize(300, 200).toFile(newPath, function(err) {
if (err) {
throw err;
}
// output.jpg is a 300 pixels wide and 200 pixels high image
// containing a scaled and cropped version of input.jpg
res.json(newPath);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With