Embed alpha image on non-transparent background #204

This commit is contained in:
Lovell Fuller 2015-04-29 20:14:45 +01:00
parent 783826aa26
commit 33782d3c83
2 changed files with 19 additions and 1 deletions

View File

@ -593,7 +593,7 @@ class ResizeWorker : public NanAsyncWorker {
} }
// Create background // Create background
VipsArrayDouble *background; VipsArrayDouble *background;
if (baton->background[3] < 255.0) { if (baton->background[3] < 255.0 || HasAlpha(image)) {
background = vips_array_double_newv( background = vips_array_double_newv(
4, baton->background[0], baton->background[1], baton->background[2], baton->background[3] 4, baton->background[0], baton->background[1], baton->background[2], baton->background[3]
); );

View File

@ -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();
});
});
});
}); });