Expose libwebp smartSubsample and reductionEffort #1545

This commit is contained in:
Lovell Fuller
2019-07-14 22:52:38 +01:00
parent 119d16cad3
commit 36e8a3da88
7 changed files with 88 additions and 3 deletions

View File

@@ -75,4 +75,54 @@ describe('WebP', function () {
fixtures.assertSimilar(fixtures.expected('webp-near-lossless-50.webp'), data50, done);
});
});
it('should produce a larger file size using smartSubsample', () =>
sharp(fixtures.inputJpg)
.resize(320, 240)
.webp({ smartSubsample: false })
.toBuffer()
.then(withoutSmartSubsample => {
sharp(fixtures.inputJpg)
.resize(320, 240)
.webp({ smartSubsample: true })
.toBuffer()
.then(withSmartSubsample => {
assert.strictEqual(true, withSmartSubsample.length > withoutSmartSubsample.length);
});
})
);
it('invalid smartSubsample throws', () => {
assert.throws(() => {
sharp().webp({ smartSubsample: 1 });
});
});
it('should produce a smaller file size with increased reductionEffort', () =>
sharp(fixtures.inputJpg)
.resize(320, 240)
.webp()
.toBuffer()
.then(reductionEffort4 => {
sharp(fixtures.inputJpg)
.resize(320, 240)
.webp({ reductionEffort: 6 })
.toBuffer()
.then(reductionEffort6 => {
assert.strictEqual(true, reductionEffort4.length > reductionEffort6.length);
});
})
);
it('invalid reductionEffort throws', () => {
assert.throws(() => {
sharp().webp({ reductionEffort: true });
});
});
it('out of range reductionEffort throws', () => {
assert.throws(() => {
sharp().webp({ reductionEffort: -1 });
});
});
});