-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to extend (pad) the edges of an image
- Loading branch information
Showing
8 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var sharp = require('../../index'); | ||
var fixtures = require('../fixtures'); | ||
|
||
describe('Extend', function () { | ||
|
||
it('extend all sides equally with RGB', function(done) { | ||
sharp(fixtures.inputJpg) | ||
.resize(120) | ||
.background({r: 255, g: 0, b: 0}) | ||
.extend(10) | ||
.toBuffer(function(err, data, info) { | ||
if (err) throw err; | ||
assert.strictEqual(140, info.width); | ||
assert.strictEqual(118, info.height); | ||
fixtures.assertSimilar(fixtures.expected('extend-equal.jpg'), data, done); | ||
}); | ||
}); | ||
|
||
it('extend sides unequally with RGBA', function(done) { | ||
sharp(fixtures.inputPngWithTransparency16bit) | ||
.resize(120) | ||
.background({r: 0, g: 0, b: 0, a: 0}) | ||
.extend({top: 50, bottom: 0, left: 10, right: 35}) | ||
.toBuffer(function(err, data, info) { | ||
if (err) throw err; | ||
assert.strictEqual(165, info.width); | ||
assert.strictEqual(170, info.height); | ||
fixtures.assertSimilar(fixtures.expected('extend-unequal.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('missing parameter fails', function() { | ||
assert.throws(function() { | ||
sharp().extend(); | ||
}); | ||
}); | ||
it('negative fails', function() { | ||
assert.throws(function() { | ||
sharp().extend(-1); | ||
}); | ||
}); | ||
it('partial object fails', function() { | ||
assert.throws(function() { | ||
sharp().extend({top: 1}); | ||
}); | ||
}); | ||
|
||
}); |