mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Use bounding box of alpha+non-alpha for trim op #2166
This commit is contained in:
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@@ -94,6 +94,7 @@ module.exports = {
|
||||
inputPngSolidAlpha: getPath('with-alpha.png'), // https://github.com/lovell/sharp/issues/1599
|
||||
inputPngP3: getPath('p3.png'), // https://github.com/lovell/sharp/issues/2862
|
||||
inputPngPalette: getPath('swiss.png'), // https://github.com/randy408/libspng/issues/188
|
||||
inputPngTrimIncludeAlpha: getPath('trim-mc.png'), // https://github.com/lovell/sharp/issues/2166
|
||||
|
||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||
|
||||
BIN
test/fixtures/trim-mc.png
vendored
Normal file
BIN
test/fixtures/trim-mc.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user