Add premultiplied option to composite operation (#1835)

This commit is contained in:
Andargor
2019-08-14 14:01:23 -04:00
committed by Lovell Fuller
parent 3fa91bb4ce
commit 4ae8999f62
10 changed files with 81 additions and 3 deletions

65
test/unit/composite.js Normal file → Executable file
View File

@@ -62,6 +62,65 @@ describe('composite', () => {
})
));
it('premultiplied true', () => {
const filename = 'composite.premultiplied.png';
const below = fixtures.path(`input.below.${filename}`);
const above = fixtures.path(`input.above.${filename}`);
const actual = fixtures.path(`output.true.${filename}`);
const expected = fixtures.expected(`expected.true.${filename}`);
return sharp(below)
.composite([{
input: above,
blend: 'color-burn',
top: 0,
left: 0,
premultiplied: true
}])
.toFile(actual)
.then(() => {
fixtures.assertMaxColourDistance(actual, expected);
});
});
it('premultiplied false', () => {
const filename = 'composite.premultiplied.png';
const below = fixtures.path(`input.below.${filename}`);
const above = fixtures.path(`input.above.${filename}`);
const actual = fixtures.path(`output.false.${filename}`);
const expected = fixtures.expected(`expected.false.${filename}`);
return sharp(below)
.composite([{
input: above,
blend: 'color-burn',
top: 0,
left: 0,
premultiplied: false
}])
.toFile(actual)
.then(() => {
fixtures.assertMaxColourDistance(actual, expected);
});
});
it('premultiplied absent', () => {
const filename = 'composite.premultiplied.png';
const below = fixtures.path(`input.below.${filename}`);
const above = fixtures.path(`input.above.${filename}`);
const actual = fixtures.path(`output.absent.${filename}`);
const expected = fixtures.expected(`expected.absent.${filename}`);
return sharp(below)
.composite([{
input: above,
blend: 'color-burn',
top: 0,
left: 0
}])
.toFile(actual)
.then(() => {
fixtures.assertMaxColourDistance(actual, expected);
});
});
it('multiple', () => {
const filename = 'composite-multiple.png';
const actual = fixtures.path(`output.${filename}`);
@@ -265,6 +324,12 @@ describe('composite', () => {
}, /Expected boolean for tile but received invalid of type string/);
});
it('invalid premultiplied', () => {
assert.throws(() => {
sharp().composite([{ input: 'test', premultiplied: 'invalid' }]);
}, /Expected boolean for premultiplied but received invalid of type string/);
});
it('invalid left', () => {
assert.throws(() => {
sharp().composite([{ input: 'test', left: 0.5 }]);