Add support for animated WebP and GIF (via magick) (#2012)

This commit is contained in:
Tomáš Szabo
2020-08-17 15:48:38 +02:00
committed by GitHub
parent 45653ca2e7
commit cb1baede87
12 changed files with 328 additions and 7 deletions

View File

@@ -125,4 +125,63 @@ describe('WebP', function () {
sharp().webp({ reductionEffort: -1 });
});
});
it('invalid pageHeight throws', () => {
assert.throws(() => {
sharp().webp({ pageHeight: 0 });
});
});
it('invalid loop throws', () => {
assert.throws(() => {
sharp().webp({ loop: -1 });
});
assert.throws(() => {
sharp().webp({ loop: 65536 });
});
});
it('invalid delay throws', () => {
assert.throws(() => {
sharp().webp({ delay: [-1] });
});
assert.throws(() => {
sharp().webp({ delay: [65536] });
});
});
it('should double the number of frames with default delay', async () => {
const original = await sharp(fixtures.inputWebPAnimated, { pages: -1 }).metadata();
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
.webp({ pageHeight: original.pageHeight / 2 })
.toBuffer()
.then(data => sharp(data, { pages: -1 }).metadata());
assert.strictEqual(updated.pages, original.pages * 2);
assert.strictEqual(updated.pageHeight, original.pageHeight / 2);
assert.deepStrictEqual(updated.delay, [...original.delay, ...Array(9).fill(120)]);
});
it('should limit animation loop', async () => {
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
.webp({ loop: 3 })
.toBuffer()
.then(data => sharp(data, { pages: -1 }).metadata());
assert.strictEqual(updated.loop, 3);
});
it('should change delay between frames', async () => {
const original = await sharp(fixtures.inputWebPAnimated, { pages: -1 }).metadata();
const expectedDelay = [...Array(original.pages).fill(40)];
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
.webp({ delay: expectedDelay })
.toBuffer()
.then(data => sharp(data, { pages: -1 }).metadata());
assert.deepStrictEqual(updated.delay, expectedDelay);
});
});