mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Embed alpha image on non-transparent background #204
This commit is contained in:
parent
783826aa26
commit
33782d3c83
@ -593,7 +593,7 @@ class ResizeWorker : public NanAsyncWorker {
|
||||
}
|
||||
// Create background
|
||||
VipsArrayDouble *background;
|
||||
if (baton->background[3] < 255.0) {
|
||||
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
||||
background = vips_array_double_newv(
|
||||
4, baton->background[0], baton->background[1], baton->background[2], baton->background[3]
|
||||
);
|
||||
|
@ -50,4 +50,22 @@ describe('Embed', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('PNG with alpha channel', function(done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(50, 50)
|
||||
.embed()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(50, info.width);
|
||||
assert.strictEqual(50, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user