Expose GIF opts: interFrameMaxError, interPaletteMaxError #3401

This commit is contained in:
Lovell Fuller
2022-11-14 16:09:52 +00:00
parent a9d692fb43
commit 5740f4545e
8 changed files with 81 additions and 1 deletions

View File

@@ -141,6 +141,28 @@ describe('GIF input', () => {
});
});
it('invalid interFrameMaxError throws', () => {
assert.throws(
() => sharp().gif({ interFrameMaxError: 33 }),
/Expected number between 0.0 and 32.0 for interFrameMaxError but received 33 of type number/
);
assert.throws(
() => sharp().gif({ interFrameMaxError: 'fail' }),
/Expected number between 0.0 and 32.0 for interFrameMaxError but received fail of type string/
);
});
it('invalid interPaletteMaxError throws', () => {
assert.throws(
() => sharp().gif({ interPaletteMaxError: 257 }),
/Expected number between 0.0 and 256.0 for interPaletteMaxError but received 257 of type number/
);
assert.throws(
() => sharp().gif({ interPaletteMaxError: 'fail' }),
/Expected number between 0.0 and 256.0 for interPaletteMaxError but received fail of type string/
);
});
it('should work with streams when only animated is set', function (done) {
fs.createReadStream(fixtures.inputGifAnimated)
.pipe(sharp({ animated: true }))
@@ -164,4 +186,18 @@ describe('GIF input', () => {
fixtures.assertSimilar(fixtures.inputGifAnimated, data, done);
});
});
it('should optimise file size via interFrameMaxError', async () => {
const input = sharp(fixtures.inputGifAnimated, { animated: true });
const before = await input.gif({ interFrameMaxError: 0 }).toBuffer();
const after = await input.gif({ interFrameMaxError: 10 }).toBuffer();
assert.strict(before.length > after.length);
});
it('should optimise file size via interPaletteMaxError', async () => {
const input = sharp(fixtures.inputGifAnimated, { animated: true });
const before = await input.gif({ interPaletteMaxError: 0 }).toBuffer();
const after = await input.gif({ interPaletteMaxError: 100 }).toBuffer();
assert.strict(before.length > after.length);
});
});