mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Allow non-RGB input to embed/extend onto bg with alpha #646
This commit is contained in:
BIN
test/fixtures/cielab-dagams.tiff
vendored
Normal file
BIN
test/fixtures/cielab-dagams.tiff
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/expected/embed-lab-into-rgba.png
vendored
Normal file
BIN
test/fixtures/expected/embed-lab-into-rgba.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@@ -83,6 +83,7 @@ module.exports = {
|
||||
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
|
||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||
inputGifGreyPlusAlpha: getPath('grey-plus-alpha.gif'), // http://i.imgur.com/gZ5jlmE.gif
|
||||
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
||||
|
||||
@@ -22,24 +22,22 @@ describe('Embed', function () {
|
||||
});
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.buffer) {
|
||||
it('JPEG within WebP, to include alpha channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.background({r: 0, g: 0, b: 0, alpha: 0})
|
||||
.embed()
|
||||
.webp()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
assert.strictEqual(4, info.channels);
|
||||
fixtures.assertSimilar(fixtures.expected('embed-3-into-4.webp'), data, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
it('JPEG within WebP, to include alpha channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.background({r: 0, g: 0, b: 0, alpha: 0})
|
||||
.embed()
|
||||
.webp()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
assert.strictEqual(4, info.channels);
|
||||
fixtures.assertSimilar(fixtures.expected('embed-3-into-4.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
@@ -103,6 +101,23 @@ describe('Embed', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('embed TIFF in LAB colourspace onto RGBA background', function (done) {
|
||||
sharp(fixtures.inputTiffCielab)
|
||||
.resize(64, 128)
|
||||
.embed()
|
||||
.background({r: 255, g: 102, b: 0, alpha: 0.5})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(64, info.width);
|
||||
assert.strictEqual(128, info.height);
|
||||
assert.strictEqual(4, info.channels);
|
||||
fixtures.assertSimilar(fixtures.expected('embed-lab-into-rgba.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Enlarge and embed', function (done) {
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.embed()
|
||||
|
||||
Reference in New Issue
Block a user