mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Add WebP 'exact' option for control over transparent pixels
This commit is contained in:
@@ -548,8 +548,8 @@ sharp('input.tiff').jxl({ decodingTier: 4 }).toFile('out.jxl');
|
||||
sharp('input.tiff').jxl({ lossless: true }).toFile('out.jxl');
|
||||
sharp('input.tiff').jxl({ effort: 7 }).toFile('out.jxl');
|
||||
|
||||
// Support `minSize` and `mixed` webp options
|
||||
sharp('input.tiff').webp({ minSize: true, mixed: true }).toFile('out.gif');
|
||||
// Support webp options
|
||||
sharp('input.tiff').webp({ minSize: true, mixed: true, exact: true }).toFile('out.webp');
|
||||
|
||||
// 'failOn' input param
|
||||
sharp('input.tiff', { failOn: 'none' });
|
||||
|
||||
@@ -213,6 +213,33 @@ describe('WebP', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('valid exact', () => {
|
||||
assert.doesNotThrow(() => sharp().webp({ exact: true }));
|
||||
});
|
||||
|
||||
it('invalid exact throws', () => {
|
||||
assert.throws(
|
||||
() => sharp().webp({ exact: 'fail' }),
|
||||
/Expected boolean for webpExact but received fail of type string/
|
||||
);
|
||||
});
|
||||
|
||||
it('saving exact pixel colour values produces larger file size', async () => {
|
||||
const withExact = await
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.resize(8, 8)
|
||||
.webp({ exact: true, effort: 0 })
|
||||
.toBuffer();
|
||||
|
||||
const withoutExact = await
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.resize(8, 8)
|
||||
.webp({ exact: false, effort: 0 })
|
||||
.toBuffer()
|
||||
|
||||
assert.strictEqual(true, withExact.length > withoutExact.length);
|
||||
});
|
||||
|
||||
it('invalid loop throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().webp({ loop: -1 });
|
||||
|
||||
Reference in New Issue
Block a user