Hello.
Sharp('dog.jpg')
.resize({width: 500, withoutEnlargement: true})
.jpeg({quality: 10, progressive: true})
.webp({quality: 50, lossless: true})
.png({quality: 50, compressionLevel: 8})
.toFile(path.join(filepath, fieldname, size, filename),
function (err) {
console.log(err);
});
Original: 44 KB

Quality 10%: 270 KB

How to compress JPEG image?
Hello, the output you've posted here is PNG rather than JPEG, hence the larger size. PNG is lossless and does not have a quality setting.
Did you see the force option on the jpeg(), webp() and png() functions? You'll probably want to set it to force: false for all three if you're specifying all three.
@lovell Thank you very much.
Sharp('dog.jpg')
.resize({width: 500, withoutEnlargement: true})
.jpeg({quality: 80, progressive: true, force: false})
.webp({quality: 80, lossless: true, force: false})
.png({quality: 80, compressionLevel: 8, force: false})
.toFile(path.join(filepath, fieldname, size, filename),
function (err) {
console.log(err);
});
Quality 80%: 18 KB

Most helpful comment
@lovell Thank you very much.
Quality 80%: 18 KB