don't call .jpeg quality on pngs

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 38ca8b481c
commit a73bcabad8

@ -32,19 +32,23 @@ image.resizeImage = function (data, callback) {
callback(err); callback(err);
}); });
} else { } else {
var sharpImage;
async.waterfall([ async.waterfall([
function (next) { function (next) {
fs.readFile(data.path, next); fs.readFile(data.path, next);
}, },
function (buffer, next) { function (buffer, next) {
var sharp = requireSharp(); var sharp = requireSharp();
var sharpImage = sharp(buffer, { sharpImage = sharp(buffer, {
failOnError: true, failOnError: true,
}); });
sharpImage.metadata(next);
},
function (metadata, next) {
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) { if (data.quality && metadata.format === 'jpeg') {
sharpImage.jpeg({ quality: data.quality }); sharpImage.jpeg({ quality: data.quality });
} }

Loading…
Cancel
Save