mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 02:30:12 +02:00
Ensure fit=contain resizing supports multiple alpha channels #4382
This commit is contained in:
parent
32872ef840
commit
94481a967e
@ -18,6 +18,9 @@ Requires libvips v8.16.1
|
||||
[#4375](https://github.com/lovell/sharp/pull/4375)
|
||||
[@hans00](https://github.com/hans00)
|
||||
|
||||
* Ensure resizing with a `fit` of `contain` supports multiple alpha channels.
|
||||
[#4382](https://github.com/lovell/sharp/issues/4382)
|
||||
|
||||
* TypeScript: Ensure `metadata` response more closely matches reality.
|
||||
[#4383](https://github.com/lovell/sharp/issues/4383)
|
||||
|
||||
|
@ -1001,9 +1001,11 @@ namespace sharp {
|
||||
0.0722 * colour[2])
|
||||
};
|
||||
}
|
||||
// Add alpha channel to alphaColour colour
|
||||
// Add alpha channel(s) to alphaColour colour
|
||||
if (colour[3] < 255.0 || image.has_alpha()) {
|
||||
alphaColour.push_back(colour[3] * multiplier);
|
||||
do {
|
||||
alphaColour.push_back(colour[3] * multiplier);
|
||||
} while (alphaColour.size() < static_cast<size_t>(image.bands()));
|
||||
}
|
||||
// Ensure alphaColour colour uses correct colourspace
|
||||
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
||||
|
@ -806,4 +806,33 @@ describe('Resize fit=contain', function () {
|
||||
fixtures.assertSimilar(fixtures.expected('./embedgravitybird/9-c.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('multiple alpha channels', async () => {
|
||||
const create = {
|
||||
width: 20,
|
||||
height: 12,
|
||||
channels: 4,
|
||||
background: 'green'
|
||||
};
|
||||
const multipleAlphaChannels = await sharp({ create })
|
||||
.joinChannel({ create })
|
||||
.tiff({ compression: 'deflate' })
|
||||
.toBuffer();
|
||||
|
||||
const data = await sharp(multipleAlphaChannels)
|
||||
.resize({
|
||||
width: 8,
|
||||
height: 8,
|
||||
fit: 'contain',
|
||||
background: 'blue'
|
||||
})
|
||||
.tiff({ compression: 'deflate' })
|
||||
.toBuffer();
|
||||
const { format, width, height, space, channels } = await sharp(data).metadata();
|
||||
assert.deepStrictEqual(format, 'tiff');
|
||||
assert.deepStrictEqual(width, 8);
|
||||
assert.deepStrictEqual(height, 8);
|
||||
assert.deepStrictEqual(space, 'srgb');
|
||||
assert.deepStrictEqual(channels, 8);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user