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 }); }