Add named 'alpha' channel to extractChannel op #2138

This commit is contained in:
Lovell Fuller
2020-06-07 10:43:27 +01:00
parent 7f142bddb3
commit 17ea70a102
6 changed files with 28 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -80,6 +80,19 @@ describe('Image channel extraction', function () {
});
});
it('Alpha from 2-channel input', function (done) {
const output = fixtures.path('output.extract-alpha-2-channel.png');
sharp(fixtures.inputPngWithGreyAlpha)
.extractChannel('alpha')
.toColourspace('b-w')
.toFile(output, function (err, info) {
if (err) throw err;
assert.strictEqual(1, info.channels);
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-alpha-2-channel.png'));
done();
});
});
it('Invalid channel number', function () {
assert.throws(function () {
sharp(fixtures.inputJpg)