Ensure trim is no-op when it would reduce to nothing #3223

This commit is contained in:
Lovell Fuller
2022-07-08 21:06:58 +01:00
parent 6c2e2be41d
commit cbf741cac7
5 changed files with 29 additions and 3 deletions

View File

@@ -140,6 +140,25 @@ describe('Trim borders', function () {
assert.strictEqual(trimOffsetLeft, -13);
});
it('Ensure trim of image with all pixels same is no-op', async () => {
const { info } = await sharp({
create: {
width: 5,
height: 5,
channels: 3,
background: 'red'
}
})
.trim()
.toBuffer({ resolveWithObject: true });
const { width, height, trimOffsetTop, trimOffsetLeft } = info;
assert.strictEqual(width, 5);
assert.strictEqual(height, 5);
assert.strictEqual(trimOffsetTop, 0);
assert.strictEqual(trimOffsetLeft, 0);
});
describe('Invalid thresholds', function () {
[-1, 'fail', {}].forEach(function (threshold) {
it(JSON.stringify(threshold), function () {