From a73bcabad80e8ae3578598364cbdf2630435da54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 24 Oct 2018 10:03:00 -0400 Subject: [PATCH] don't call .jpeg quality on pngs --- src/image.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/image.js b/src/image.js index 5c2d233e90..7789caa0b6 100644 --- a/src/image.js +++ b/src/image.js @@ -32,19 +32,23 @@ image.resizeImage = function (data, callback) { callback(err); }); } else { + var sharpImage; async.waterfall([ function (next) { fs.readFile(data.path, next); }, function (buffer, next) { var sharp = requireSharp(); - var sharpImage = sharp(buffer, { + sharpImage = sharp(buffer, { failOnError: true, }); + sharpImage.metadata(next); + }, + function (metadata, next) { sharpImage.rotate(); // auto-orients based on exif data 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 }); }