Expose PNG output options requiring libimagequant #1484

This commit is contained in:
Lovell Fuller
2019-01-12 18:26:53 +00:00
parent bd377438b6
commit 98797445de
8 changed files with 211 additions and 74 deletions

View File

@@ -628,78 +628,6 @@ describe('Input/output', function () {
});
});
describe('PNG output', function () {
it('compression level is valid', function () {
assert.doesNotThrow(function () {
sharp().png({ compressionLevel: 0 });
});
});
it('compression level is invalid', function () {
assert.throws(function () {
sharp().png({ compressionLevel: -1 });
});
});
it('default compressionLevel generates smaller file than compressionLevel=6', function (done) {
// First generate with default compressionLevel
sharp(fixtures.inputPng)
.resize(320, 240)
.png()
.toBuffer(function (err, defaultData, defaultInfo) {
if (err) throw err;
assert.strictEqual(true, defaultData.length > 0);
assert.strictEqual('png', defaultInfo.format);
// Then generate with compressionLevel=6
sharp(fixtures.inputPng)
.resize(320, 240)
.png({ compressionLevel: 6 })
.toBuffer(function (err, largerData, largerInfo) {
if (err) throw err;
assert.strictEqual(true, largerData.length > 0);
assert.strictEqual('png', largerInfo.format);
assert.strictEqual(true, defaultData.length < largerData.length);
done();
});
});
});
it('without adaptiveFiltering generates smaller file', function (done) {
// First generate with adaptive filtering
sharp(fixtures.inputPng)
.resize(320, 240)
.png({ adaptiveFiltering: true })
.toBuffer(function (err, adaptiveData, adaptiveInfo) {
if (err) throw err;
assert.strictEqual(true, adaptiveData.length > 0);
assert.strictEqual(adaptiveData.length, adaptiveInfo.size);
assert.strictEqual('png', adaptiveInfo.format);
assert.strictEqual(320, adaptiveInfo.width);
assert.strictEqual(240, adaptiveInfo.height);
// Then generate without
sharp(fixtures.inputPng)
.resize(320, 240)
.png({ adaptiveFiltering: false })
.toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) {
if (err) throw err;
assert.strictEqual(true, withoutAdaptiveData.length > 0);
assert.strictEqual(withoutAdaptiveData.length, withoutAdaptiveInfo.size);
assert.strictEqual('png', withoutAdaptiveInfo.format);
assert.strictEqual(320, withoutAdaptiveInfo.width);
assert.strictEqual(240, withoutAdaptiveInfo.height);
assert.strictEqual(true, withoutAdaptiveData.length < adaptiveData.length);
done();
});
});
});
it('Invalid PNG adaptiveFiltering value throws error', function () {
assert.throws(function () {
sharp().png({ adaptiveFiltering: 1 });
});
});
});
it('Without chroma subsampling generates larger file', function (done) {
// First generate with chroma subsampling (default)
sharp(fixtures.inputJpg)