From d0e6a4c0f35649e7b940ec4fe7c46c9faa9c761c Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 4 Mar 2014 22:44:53 +0000 Subject: [PATCH] Support identity transform when both width and height are not specified --- index.js | 4 ---- src/sharp.cc | 7 ++++--- tests/unit.js | 58 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index fa8ab09d..55ed7f48 100755 --- a/index.js +++ b/index.js @@ -42,10 +42,6 @@ module.exports.resize = function(input, output, width, height, options, callback callback("Invalid height " + height); return; } - if (outWidth < 1 && outHeight < 1) { - callback("Width and/or height required"); - return; - } var canvas = options.canvas || "c"; if (canvas.length !== 1 || "cwb".indexOf(canvas) === -1) { callback("Invalid canvas " + canvas); diff --git a/src/sharp.cc b/src/sharp.cc index 67110015..74b8f52e 100755 --- a/src/sharp.cc +++ b/src/sharp.cc @@ -132,9 +132,10 @@ void resize_async(uv_work_t *work) { factor = yfactor; baton->width = floor(in->Xsize * factor); } else { - resize_error(baton, in); - (baton->err).append("Width and/or height required"); - return; + // Identity transform + factor = 1; + baton->width = in->Xsize; + baton->height = in->Ysize; } factor = std::max(factor, 1.0); diff --git a/tests/unit.js b/tests/unit.js index 3a9b82e9..aef95a43 100755 --- a/tests/unit.js +++ b/tests/unit.js @@ -1,34 +1,54 @@ var sharp = require("../index"); var imagemagick = require("imagemagick"); var assert = require("assert"); +var async = require("async"); var inputJpg = __dirname + "/2569067123_aca715a2ee_o.jpg"; // http://www.flickr.com/photos/grizdave/2569067123/ var outputJpg = __dirname + "/output.jpg"; -sharp.resize(inputJpg, outputJpg, 320, 240, function(err) { - if (err) throw err; - imagemagick.identify(outputJpg, function(err, features) { - if (err) throw err; - assert.strictEqual(320, features.width); - assert.strictEqual(240, features.height); - +async.series([ + function(done) { + sharp.resize(inputJpg, outputJpg, 320, 240, function(err) { + if (err) throw err; + imagemagick.identify(outputJpg, function(err, features) { + if (err) throw err; + assert.strictEqual(320, features.width); + assert.strictEqual(240, features.height); + done(); + }); + }); + }, + function(done) { sharp.resize(inputJpg, outputJpg, 320, -1, function(err) { if (err) throw err; imagemagick.identify(outputJpg, function(err, features) { if (err) throw err; assert.strictEqual(320, features.width); assert.strictEqual(262, features.height); + done(); }); - - sharp.resize(inputJpg, outputJpg, -1, 320, function(err) { - if (err) throw err; - imagemagick.identify(outputJpg, function(err, features) { - if (err) throw err; - assert.strictEqual(392, features.width); - assert.strictEqual(320, features.height); - }); - }); - }); - }); -}); + }, + function(done) { + sharp.resize(inputJpg, outputJpg, -1, 320, function(err) { + if (err) throw err; + imagemagick.identify(outputJpg, function(err, features) { + if (err) throw err; + assert.strictEqual(392, features.width); + assert.strictEqual(320, features.height); + done(); + }); + }); + }, + function(done) { + sharp.resize(inputJpg, outputJpg, -1, -1, function(err) { + if (err) throw err; + imagemagick.identify(outputJpg, function(err, features) { + if (err) throw err; + assert.strictEqual(2725, features.width); + assert.strictEqual(2225, features.height); + done(); + }); + }); + } +]);