Animation keeps one frame or becomes a tall image
A first-frame-only result, a tall strip, and misaligned frames after resizing require separate checks: loaded page count, page height, and timing metadata. This three-frame GIF makes frame order directly visible.
Inspect the generated outputs
Section titled “Inspect the generated outputs”The frames have red, green, and blue backgrounds, one, two, and three white bars, and a moving marker. Each frame is 320×180 with delays of 200 / 400 / 600 ms and infinite looping. Animations initially show their exported first frame; use the button to play or stop. The tall strip and metadata also expose frame structure without playback.
govips v2.20.0 / libvips 8.17.3

{"Bitdepth":8,"Dither":0,"Effort":7,"NumPages":-1,"pageHeight":180,"resize":false}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"Bitdepth":8,"Dither":0,"Effort":7,"NumPages":1,"pageHeight":180,"resize":false}Download generated output
{"Bitdepth":8,"Dither":0,"Effort":7,"NumPages":-1,"pageHeight":180,"resize":false}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"Bitdepth":8,"Dither":0,"Effort":7,"NumPages":-1,"pageHeight":540,"resize":false}Download generated output
{"Bitdepth":8,"Dither":0,"Effort":7,"NumPages":-1,"pageHeight":90,"resize":true}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated outputsharp 0.35.5 / libvips 8.18.7

{"animated":true,"colours":256,"dither":0,"effort":7,"delay":[200,400,600],"loop":0}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"animated":false}Download generated output
{"animated":true,"colours":256,"dither":0,"effort":7,"delay":[200,400,600],"loop":0}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"raw":true,"pageHeight":"omitted"}Download generated output
{"animated":true,"width":160,"pageHeight":90,"colours":256,"dither":0,"effort":7,"delay":[200,400,600],"loop":0}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated outputpyvips 3.2.0 / libvips 8.17.3

{"n":-1,"bitdepth":8,"dither":0,"effort":7}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"n":1,"bitdepth":8,"dither":0,"effort":7}Download generated output
{"n":-1,"bitdepth":8,"dither":0,"effort":7}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"page-height":"omitted","bitdepth":8,"dither":0,"effort":7}Download generated output
{"n":-1,"scale":0.5,"page-height":90,"bitdepth":8,"dither":0,"effort":7}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated outputvipsCli 8.17.3 / libvips 8.17.3

{"n":-1,"page-height":180}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"n":1,"page-height":180}Download generated output
{"n":-1,"page-height":180}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated output
{"n":-1,"page-height":"omitted"}Download generated output
{"n":-1,"page-height":90}Frames: 3 · 200 / 400 / 600 ms · Loop: infiniteDownload generated outputSeparate the three failure modes
Section titled “Separate the three failure modes”| Visible symptom | Controlled change | Correction |
|---|---|---|
| Only the red first frame remains | Load one page only | Set govips NumPages=-1, pyvips/CLI n=-1, or sharp animated: true explicitly |
| Three frames become one 320×540 image | Reconstruct all decoded pixels as a raw image without a per-frame height | Set the correct page-height, delay, and loop when rebuilding the animation; sharp raw input uses raw.pageHeight |
| Frame boundaries are wrong after resizing | Page height does not follow the per-frame geometry | Here the resized result must contain three 160×90 frames; the CLI uses the save option page-height=90, while pyvips explicitly updates the image field |
The libvips multipage model stacks frames vertically. Loading this entire source produces a total decoded height of 540 and a page-height of 180. Those dimensions describe different things. Copying raw pixels alone does not retain page count, frame height, or timing information.
Load, transform, and export correctly
Section titled “Load, transform, and export correctly”The govips v2.20.0 example loads every frame before resizing and preserves frame boundaries. Sharp applies its own animation-aware resizing. Pyvips and the CLI explicitly correct the resized page height. A convenience wrapper in one binding does not establish defaults for the others.
The complete programs generate both the failure cases and corrected outputs. Reconstructing the raw tall image is a controlled failure, rather than a required step for ordinary animation conversion.
Run command
go run . three-frames.gif output/Complete source
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/davidbyttow/govips/v2/vips"
"github.com/webp-sh/vips-handbook/examples/internal/recipeutil"
)
func main() {
if err := run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(args []string) error {
if len(args) != 3 {
return fmt.Errorf("usage: main INPUT OUTPUT_DIRECTORY")
}
if err := os.MkdirAll(args[2], 0o755); err != nil {
return err
}
if err := vips.Startup(nil); err != nil {
return err
}
defer vips.Shutdown()
outputs := []recipeutil.Output{}
for _, id := range []string{"source", "first-frame", "all-frames", "tall-strip", "resized"} {
output, err := makeVariant(args[1], args[2], id)
if err != nil {
return err
}
outputs = append(outputs, output)
}
return recipeutil.WriteResult(args[2], "animation-pages", args[1], outputs)
}
func makeVariant(input, dir, id string) (recipeutil.Output, error) {
params := vips.NewImportParams()
if id != "first-frame" {
params.NumPages.Set(-1)
}
image, err := vips.LoadImageFromFile(input, params)
if err != nil {
return recipeutil.Output{}, err
}
defer func() { image.Close() }()
if id == "tall-strip" {
pixels, err := image.ToBytes()
if err != nil {
return recipeutil.Output{}, err
}
tall, err := vips.NewImageFromMemory(pixels, image.Width(), image.Height(), image.Bands(), vips.BandFormatUchar, vips.InterpretationSRGB)
if err != nil {
return recipeutil.Output{}, err
}
image.Close()
image = tall
// No SetPageHeight: the new raw image is a single tall page.
}
if id == "resized" {
if err := image.Resize(0.5, vips.KernelNearest); err != nil {
return recipeutil.Output{}, err
}
}
if id == "all-frames" || id == "resized" || id == "source" {
if err := image.SetPageDelay([]int{200, 400, 600}); err != nil {
return recipeutil.Output{}, err
}
if err := image.SetLoop(0); err != nil {
return recipeutil.Output{}, err
}
}
export := vips.NewGifExportParams()
export.Dither = 0
export.Bitdepth = 8
export.Effort = 7
data, meta, err := image.ExportGIF(export)
if err != nil {
return recipeutil.Output{}, err
}
name := id + ".gif"
if err := os.WriteFile(filepath.Join(dir, name), data, 0o644); err != nil {
return recipeutil.Output{}, err
}
n := 1
if id != "first-frame" {
n = -1
}
return recipeutil.Output{Path: name, Format: "gif", Width: meta.Width, Height: meta.Height, Size: len(data), Parameters: map[string]any{"NumPages": n, "resize": id == "resized", "pageHeight": image.PageHeight(), "Dither": 0, "Bitdepth": 8, "Effort": 7}}, nil
}Run command
node index.mjs three-frames.gif output/Complete source
import sharp from 'sharp';
import { mkdir, writeFile } from 'node:fs/promises';
import path from 'node:path';
const [input, out] = process.argv.slice(2);
if (!input || !out) throw new Error('usage: node index.mjs INPUT OUTPUT_DIRECTORY');
await mkdir(out, { recursive: true });
const outputs = [];
async function save(pipeline, name, parameters) {
await pipeline.toFile(path.join(out, name));
outputs.push({ path: name, parameters });
}
const options = { colours: 256, dither: 0, effort: 7, delay: [200, 400, 600], loop: 0 };
await save(sharp(input, { animated: true }).gif(options), 'source.gif', { animated: true, ...options });
await save(sharp(input).gif({ colours: 256, dither: 0, effort: 7 }), 'first-frame.gif', { animated: false });
await save(sharp(input, { animated: true }).gif(options), 'all-frames.gif', { animated: true, ...options });
await save(sharp(input, { animated: true }).resize(160, 90, { kernel: 'nearest' }).gif(options), 'resized.gif', { animated: true, width: 160, pageHeight: 90, ...options });
const { data, info } = await sharp(input, { animated: true }).raw().toBuffer({ resolveWithObject: true });
// Deliberately omit raw.pageHeight: 540 rows now represent one tall frame.
await save(sharp(data, { raw: { width: info.width, height: info.height, channels: info.channels } }).gif({ colours: 256, dither: 0, effort: 7 }), 'tall-strip.gif', { raw: true, pageHeight: 'omitted' });
await writeFile(path.join(out, 'result.json'), JSON.stringify({ recipeId: 'animation-pages', input: path.basename(input), generator: { sharp: sharp.versions.sharp, libvips: sharp.versions.vips }, outputs }, null, 2) + '\n');Run command
python3 main.py three-frames.gif output/Complete source
import json
from pathlib import Path
import sys
import pyvips
if len(sys.argv) != 3:
raise SystemExit("usage: python3 main.py INPUT OUTPUT_DIRECTORY")
source, out = Path(sys.argv[1]), Path(sys.argv[2])
out.mkdir(parents=True, exist_ok=True)
outputs = []
def record(name, parameters):
outputs.append({"path": name, "parameters": parameters})
options = dict(bitdepth=8, dither=0, effort=7)
image = pyvips.Image.new_from_file(str(source), n=-1)
image.gifsave(str(out / "source.gif"), **options)
record("source.gif", {"n": -1, **options})
pyvips.Image.new_from_file(str(source)).gifsave(str(out / "first-frame.gif"), **options)
record("first-frame.gif", {"n": 1, **options})
image.gifsave(str(out / "all-frames.gif"), **options)
record("all-frames.gif", {"n": -1, **options})
small = image.resize(0.5, kernel="nearest")
small.set_type(pyvips.GValue.gint_type, "page-height", 90)
small.gifsave(str(out / "resized.gif"), **options)
record("resized.gif", {"n": -1, "scale": 0.5, "page-height": 90, **options})
tall = pyvips.Image.new_from_memory(image.write_to_memory(), image.width, image.height, image.bands, "uchar").copy(interpretation="srgb")
# No page-height metadata is attached to this reconstructed raw image.
tall.gifsave(str(out / "tall-strip.gif"), **options)
record("tall-strip.gif", {"page-height": "omitted", **options})
(out / "result.json").write_text(json.dumps({"recipeId": "animation-pages", "input": source.name, "generator": {"pyvips": pyvips.__version__, "libvips": ".".join(str(pyvips.version(i)) for i in range(3))}, "outputs": outputs}, indent=2) + "\n")Run command
bash run.sh three-frames.gif output/Complete source
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo 'usage: bash run.sh INPUT OUTPUT_DIRECTORY' >&2
exit 2
fi
input="$1"
out="$2"
mkdir -p "$out"
scratch="$(mktemp -d)"
trap 'rm -rf "$scratch"' EXIT
vips gifsave "$input[n=-1]" "$out/source.gif" --bitdepth 8 --dither 0 --effort 7
vips gifsave "$input" "$out/first-frame.gif" --bitdepth 8 --dither 0 --effort 7
vips gifsave "$input[n=-1]" "$out/all-frames.gif" --bitdepth 8 --dither 0 --effort 7
vips resize "$input[n=-1]" "$scratch/resized.v" 0.5 --kernel nearest
vips gifsave "$scratch/resized.v" "$out/resized.gif" --page-height 90 --bitdepth 8 --dither 0 --effort 7
# Raw pixels carry no frame height, delay, or loop metadata.
vips rawsave "$input[n=-1]" "$scratch/strip.raw"
vips rawload "$scratch/strip.raw" "$scratch/strip.v" 320 540 4
vips copy "$scratch/strip.v" "$scratch/rgb.v" --interpretation srgb
vips gifsave "$scratch/rgb.v" "$out/tall-strip.gif" --bitdepth 8 --dither 0 --effort 7
python3 - "$input" "$out" <<'METADATA'
import json
from pathlib import Path
import subprocess
import sys
source, out = Path(sys.argv[1]), Path(sys.argv[2])
version = subprocess.check_output(["vips", "--version"], text=True).strip().removeprefix("vips-")
outputs = [{'path': 'source.gif', 'parameters': {'n': -1, 'page-height': 180}}, {'path': 'first-frame.gif', 'parameters': {'n': 1, 'page-height': 180}}, {'path': 'all-frames.gif', 'parameters': {'n': -1, 'page-height': 180}}, {'path': 'tall-strip.gif', 'parameters': {'n': -1, 'page-height': 'omitted'}}, {'path': 'resized.gif', 'parameters': {'n': -1, 'page-height': 90}}]
(out / "result.json").write_text(json.dumps({"recipeId": "animation-pages", "input": source.name, "generator": {"vipsCli": version, "libvips": version}, "outputs": outputs}, indent=2) + "\n")
METADATACheck frame order and timing
Section titled “Check frame order and timing”- Reload every exported frame and check three pages, with total height equal to three times page height.
- Inspect the red, green, and blue backgrounds and bar counts in order; total dimensions alone cannot detect reversed frames.
- Confirm delays remain 200 / 400 / 600 ms and loop is 0, meaning infinite looping in this example.
- Confirm that the first-frame and tall-strip cases each contain one page, rather than relying on a viewer’s presentation.
Each entry checks complete decoded pixels at the original size, resized frame order and geometry, delays, and looping. This does not establish equivalence for every animation operation.
Verification boundary and sources
Section titled “Verification boundary and sources”Reviewed on 2026-10-26. Reference: govips v2.20.0 / libvips 8.17.3. Sharp 0.35.5 uses libvips 8.18.7; pyvips 3.2.0 and the CLI use libvips 8.17.3.
This example verifies GIF with three distinct frames and an exact 0.5 scale. It does not reproduce defects in older versions or cover AVIF, PDF, multipage TIFF, duplicate-frame merging, fractional rounding, or every rotation. It provides no multipage guarantee for Similarity, SmartCrop, or Gravity.