Use bounding box of alpha+non-alpha for trim op #2166

This commit is contained in:
Lovell Fuller
2022-07-05 18:19:17 +01:00
parent e3cab7f10f
commit e0d3c6e05d
8 changed files with 44 additions and 14 deletions

View File

@@ -128,6 +128,18 @@ describe('Trim borders', function () {
)
);
it('Ensure trim uses bounding box of alpha and non-alpha channels', async () => {
const { info } = await sharp(fixtures.inputPngTrimIncludeAlpha)
.trim()
.toBuffer({ resolveWithObject: true });
const { width, height, trimOffsetTop, trimOffsetLeft } = info;
assert.strictEqual(width, 179);
assert.strictEqual(height, 123);
assert.strictEqual(trimOffsetTop, -44);
assert.strictEqual(trimOffsetLeft, -13);
});
describe('Invalid thresholds', function () {
[-1, 'fail', {}].forEach(function (threshold) {
it(JSON.stringify(threshold), function () {