mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support for animated WebP and GIF (via magick) (#2012)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user