Support identity transform when both width and height are not specified

This commit is contained in:
Lovell Fuller 2014-03-04 22:44:53 +00:00
parent f99e42d447
commit d0e6a4c0f3
3 changed files with 43 additions and 26 deletions

View File

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

View File

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

View File

@ -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";
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();
});
});
},
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();
});
});
}
]);