Add unflatten operation to create an alpha channel (#3461)

This commit is contained in:
Anton Marsden
2023-04-07 22:01:29 +12:00
committed by GitHub
parent b9c3851515
commit a4c6eba7d4
11 changed files with 93 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

37
test/unit/unflatten.js Normal file
View File

@@ -0,0 +1,37 @@
'use strict';
const sharp = require('../../');
const fixtures = require('../fixtures');
// const assert = require('assert');
describe('Unflatten', function () {
it('unflatten white background', function (done) {
sharp(fixtures.inputPng).unflatten()
.toBuffer(function (err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.expected('unflatten-white-transparent.png'), data, { threshold: 0 }, done);
});
});
it('unflatten transparent image', function (done) {
sharp(fixtures.inputPngTrimSpecificColourIncludeAlpha).unflatten()
.toBuffer(function (err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.expected('unflatten-flag-white-transparent.png'), data, { threshold: 0 }, done);
});
});
it('unflatten using threshold', function (done) {
sharp(fixtures.inputPngPalette).unflatten(true).threshold(128, { grayscale: false })
.toBuffer(function (err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.expected('unflatten-swiss.png'), data, { threshold: 1 }, done);
});
});
it('no unflatten', function (done) {
sharp(fixtures.inputPng).unflatten(false)
.toBuffer(function (err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.inputPng, data, { threshold: 0 }, done);
});
});
});