mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Add usage example and further unit test for new max option
Simplify max vs crop logic
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user