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'; const gif = 'IMG_7426.GIF'; console.log(await sharp(gif).metadata()); // default console.log(await sharp(gif, { animated: true }).metadata()); // animated Trimmed to the fields that matter:
default {"width":373,"height":498,"pages":24,"loop":0,"delay":[80,80,80]} animated {"width":373,"height":11952,"pages":24,"pageHeight":498,"loop":0,"delay":[80,80,80]} 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:
delayis 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):
const still = await sharp(gif).webp({ quality: 80 }).toBuffer(); const anim = await sharp(gif, { animated: true }).webp({ quality: 80, effort: 4 }).toBuffer(); webp without animated: 16270 {"width":373,"height":498} webp with animated: 406840 {"width":373,"height":11952,"pages":24,"pageHeight":498,"loop":0,"delay":[80,80,80]} 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:
const small = await sharp(gif, { animated: true }).resize({ width: 186 }).webp({ quality: 80, effort: 4 }).toBuffer(); resized {"bytes":146990,"width":186,"height":5952,"pages":24,"pageHeight":248,"loop":0,"delay":[80,80,80]} 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:
for (const p of [0, 11, 23]) { const f = await sharp(gif, { page: p }).png().toBuffer(); console.log('page', p, f.length); } frames {"page0":137047,"page11":139332,"page23":141184} 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).
const retimed = await sharp(gif, { animated: true }) .webp({ quality: 80, effort: 4, delay: Array(24).fill(40), loop: 3 }).toBuffer(); retimed {"width":373,"height":11952,"pages":24,"pageHeight":498,"loop":3,"delay":[40,40,40]} The animation now plays at twice the speed and stops after three loops.
How do I drop frames?
Halve the frame rate by keeping every second frame and doubling the delay. Pull raw RGBA, slice the strip into frames, and rebuild it with pageHeight in the raw input:
const meta = await sharp(gif, { animated: true }).metadata(); const w = meta.width, h = meta.pageHeight; const raw = await sharp(gif, { animated: true }).ensureAlpha().raw().toBuffer({ resolveWithObject: true }); const frameBytes = w * h * 4; const keep = []; for (let i = 0; i < meta.pages; i += 2) keep.push(raw.data.subarray(i * frameBytes, (i + 1) * frameBytes)); const half = await sharp(Buffer.concat(keep), { raw: { width: w, height: h * keep.length, channels: 4, pageHeight: h } }) .webp({ quality: 80, effort: 4, delay: Array(keep.length).fill(160), loop: 0 }).toBuffer(); half {"bytes":203288,"width":373,"height":5976,"pages":12,"pageHeight":498,"loop":0,"delay":[160,160,160]} 12 frames at 160 ms. The file is 203,288 bytes, half of the full-rate 406,840. The motion is choppier, so judge it by eye. I did not.
For the format background, see what WebP is and how to save a GIF.
How I measured
- Node v24.22.0, sharp 0.35.4 (libvips 8.18.6, libwebp 1.6.0, cgif 0.5.3), Apple M1 Pro, 2026-10-18.
- Input: one 24-frame, 373 × 498 GIF (2,817,469 bytes) from my downloads folder.
-
sharp.cache(false). Byte counts only; each number is a single run (encoding is deterministic here). - Raw numbers:
measured.jsonin this folder.
What I did not test
Animated AVIF, APNG, and animated WebP as input to other tools. Visual quality of the lower-quality or half-rate outputs. Browser playback and timing of the retimed file. Encode time.
I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

