Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,13 @@ function recomb (inputMatrix) {
if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
}
const recombMatrix = inputMatrix.flat().map(Number);
const recombMatrix = inputMatrix.flat();
if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
}
if (!recombMatrix.every(is.number)) {
throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
}
this.options.recombMatrix = recombMatrix;
return this;
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/recomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,11 @@ suite('Recomb', () => {
sharp(fixtures.inputJpg).recomb([[1, 2, 3, 4], [5, 6, 7, 8]]);
});
});
test('non-numeric entries', (t) => {
t.plan(1);
t.assert.throws(() => {
sharp(fixtures.inputJpg).recomb([['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]]);
});
});
});
});