sharp reads only the first frame of a GIF or animated WebP unless you pass { animated: true }. With it, the image becomes a tall strip: my…

sharp reads only the first frame of a GIF or animated WebP unless you pass { animated: true }. With it, the image becomes a tall strip: my 373 × 498 GIF with 24 frames reports height: 11952, and pageHeight: 498 is the real frame height. Forget the option and a 2,817.5 KB animation becomes a single still of 16.3 KB. Forget pageHeight and your resize maths is off by a factor of 24. What does sharp return by default? I used a 24-frame GIF, 2,817,469 bytes, with 80 ms per frame.

import sharp from 'sharp'; // default // animated Trimmed to the fields that matter: default animated Both calls know there are 24 pages. Only the second treats them as an image 24 frames tall. The sharp docs define pages as the number of frames and pageHeight as "number of pixels high each page in a multi-page image will be" (input metadata). Note: delay is an array in milliseconds, one entry per frame. Pass the same unit back when you write. What happens without animated: true?

I converted the GIF to WebP both ways, same quality (80): webp without animated: 16270 {"width":373,"height":498} webp with animated: 406840 No error, no warning. The first output is a perfectly valid WebP, and it is frame 1 only. It also looks like a huge win in a size report. Check pages on the output in a test. How big is each output?

GIF input: 2,817,469 bytes WebP lossless: 2,437,650 bytes WebP q80: 406,840 bytes WebP q65: 265,852 bytes WebP q50: 218,612 bytes GIF re-encoded by sharp (effort: 7): 2,727,860 bytes Lossy WebP is the large win. Lossless WebP barely beats the GIF, and sharp's GIF encoder gave back 2,727,860 bytes, 3% under the original. If your goal is file size, change the format and accept lossy. How do I resize an animation? resize() works on the whole strip, and sharp handles the page height for you when animated is on: resized 186 × 24 frames of 248 px is 5,952.

Frame count and delays survived. Halving the width cut the file from 406,840 to 146,990 bytes. How do I pull out one frame? Use page, a zero-based index, on the input. It needs no animated flag: frames Each is a 373 × 498 PNG. Use this for poster images and thumbnails. How do I change the delay or the loop count? Both are options on the WebP encoder. The docs list loop (0 means forever) and delay as a number or array in milliseconds (output options).

Source disclosure

This is a source-linked briefing. Read the original report from Dev Community .