Add usage example and further unit test for new max option

Simplify max vs crop logic
This commit is contained in:
Lovell Fuller
2014-05-19 21:52:47 +01:00
parent ad7735a0a6
commit 276ba5228b
3 changed files with 40 additions and 18 deletions

View File

@@ -112,7 +112,7 @@ async.series([
},
// Resize to max width or height considering ratio (landscape)
function(done) {
sharp(inputJpg).resize(320,320).max().write(outputJpg, function(err) {
sharp(inputJpg).resize(320, 320).max().write(outputJpg, function(err) {
if (err) throw err;
imagemagick.identify(outputJpg, function(err, features) {
if (err) throw err;
@@ -124,7 +124,7 @@ async.series([
},
// Resize to max width or height considering ratio (portrait)
function(done) {
sharp(inputTiff).resize(320,320).max().write(outputJpg, function(err) {
sharp(inputTiff).resize(320, 320).max().write(outputJpg, function(err) {
if (err) throw err;
imagemagick.identify(outputJpg, function(err, features) {
if (err) throw err;
@@ -133,5 +133,17 @@ async.series([
done();
});
});
},
// Attempt to resize to max but only provide one dimension, so should default to crop
function(done) {
sharp(inputJpg).resize(320).max().write(outputJpg, function(err) {
if (err) throw err;
imagemagick.identify(outputJpg, function(err, features) {
if (err) throw err;
assert.strictEqual(320, features.width);
assert.strictEqual(261, features.height);
done();
});
});
}
]);