Deprecate background, add op-specific prop to resize/extend/flatten #1392

This commit is contained in:
Lovell Fuller
2018-10-01 20:58:55 +01:00
parent 6007e13a22
commit a64844689e
17 changed files with 378 additions and 296 deletions

View File

@@ -9,8 +9,13 @@ 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)
.extend({
top: 10,
bottom: 10,
left: 10,
right: 10,
background: { r: 255, g: 0, b: 0 }
})
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(140, info.width);
@@ -22,8 +27,13 @@ describe('Extend', function () {
it('extend sides unequally with RGBA', function (done) {
sharp(fixtures.inputPngWithTransparency16bit)
.resize(120)
.background({r: 0, g: 0, b: 0, alpha: 0})
.extend({top: 50, bottom: 0, left: 10, right: 35})
.extend({
top: 50,
bottom: 0,
left: 10,
right: 35,
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(165, info.width);
@@ -50,9 +60,14 @@ describe('Extend', function () {
it('should add alpha channel before extending with a transparent Background', function (done) {
sharp(fixtures.inputJpgWithLandscapeExif1)
.background({r: 0, g: 0, b: 0, alpha: 0})
.extend({
top: 0,
bottom: 10,
left: 0,
right: 10,
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
.toFormat(sharp.format.png)
.extend({top: 0, bottom: 10, left: 0, right: 10})
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(610, info.width);
@@ -63,8 +78,13 @@ describe('Extend', function () {
it('PNG with 2 channels', function (done) {
sharp(fixtures.inputPngWithGreyAlpha)
.background('transparent')
.extend({top: 0, bottom: 20, left: 0, right: 20})
.extend({
top: 0,
bottom: 20,
left: 0,
right: 20,
background: 'transparent'
})
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);