feat: additional quality options for jpeg uploads, added quality and compression settings for png uploads

isekai-main
Julian Lam 3 years ago
parent ee0282f5aa
commit d22b076b2e

@ -52,8 +52,24 @@ image.resizeImage = async function (data) {
sharpImage.rotate(); // auto-orients based on exif data sharpImage.rotate(); // auto-orients based on exif data
sharpImage.resize(data.hasOwnProperty('width') ? data.width : null, data.hasOwnProperty('height') ? data.height : null); sharpImage.resize(data.hasOwnProperty('width') ? data.width : null, data.hasOwnProperty('height') ? data.height : null);
if (data.quality && metadata.format === 'jpeg') { if (data.quality) {
sharpImage.jpeg({ quality: data.quality }); switch (metadata.format) {
case 'jpeg': {
sharpImage.jpeg({
quality: data.quality,
mozjpeg: true,
});
break;
}
case 'png': {
sharpImage.png({
quality: data.quality,
compressionLevel: 9,
});
break;
}
}
} }
await sharpImage.toFile(data.target || data.path); await sharpImage.toFile(data.target || data.path);

Loading…
Cancel
Save