mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add extractChannel operation to extract a channel from an image (#497)
This commit is contained in:
committed by
Lovell Fuller
parent
f672f86b53
commit
83d8847f57
BIN
test/fixtures/expected/extract-blue.jpg
vendored
Normal file
BIN
test/fixtures/expected/extract-blue.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/expected/extract-green.jpg
vendored
Normal file
BIN
test/fixtures/expected/extract-green.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/expected/extract-red.jpg
vendored
Normal file
BIN
test/fixtures/expected/extract-red.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
72
test/unit/extractChannel.js
Normal file
72
test/unit/extractChannel.js
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
describe('Image channel extraction', function() {
|
||||
|
||||
it('Red channel', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('red')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('extract-red.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Green channel', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('green')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('extract-green.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('blue')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('extract-blue.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel by number', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(2)
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('extract-blue.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid channel number', function() {
|
||||
assert.throws(function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('No arguments', function() {
|
||||
assert.throws(function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user