mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 19:10:14 +02:00
Merge pull request #351 from joelmukuthu/master
Fix: default crop gravity to sharp.gravity.center
This commit is contained in:
commit
320a7464c7
4
index.js
4
index.js
@ -231,7 +231,9 @@ module.exports.gravity = {
|
||||
|
||||
Sharp.prototype.crop = function(gravity) {
|
||||
this.options.canvas = 'crop';
|
||||
if (typeof gravity === 'number' && !Number.isNaN(gravity) && gravity >= 0 && gravity <= 8) {
|
||||
if (typeof gravity === 'undefined') {
|
||||
this.options.gravity = module.exports.gravity.center;
|
||||
} else if (typeof gravity === 'number' && !Number.isNaN(gravity) && gravity >= 0 && gravity <= 8) {
|
||||
this.options.gravity = gravity;
|
||||
} else if (typeof gravity === 'string' && typeof module.exports.gravity[gravity] === 'number') {
|
||||
this.options.gravity = module.exports.gravity[gravity];
|
||||
|
@ -145,4 +145,25 @@ describe('Crop gravities', function() {
|
||||
sharp(fixtures.inputJpg).crop('yadda');
|
||||
});
|
||||
});
|
||||
|
||||
it('does not throw if crop gravity is undefined', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
sharp(fixtures.inputJpg).crop();
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults crop gravity to sharp.gravity.center', function(done) {
|
||||
var centerGravitySettings = testSettings.filter(function (settings) {
|
||||
return settings.name === 'Center';
|
||||
})[0];
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(centerGravitySettings.width, centerGravitySettings.height)
|
||||
.crop()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(centerGravitySettings.width, info.width);
|
||||
assert.strictEqual(centerGravitySettings.height, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected(centerGravitySettings.fixture), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user