gohugoio/hugo · error

webp: animated image has no frames

Error message

webp: animated image has no frames

What it means

Returned by WebpCodec.Encode (internal/warpc/webp.go:273) when asked to encode an AnimatedImage whose GetFrames() returns an empty slice. An animated WebP needs at least one frame to build the pixel buffer and frame-duration list, so an empty animation is rejected as invalid input rather than silently producing an empty file.

Source

Thrown at internal/warpc/webp.go:273

	var (
		bounds         = img.Bounds()
		imageBytes     []byte
		stride         int
		frameDurations []int
		loopCount      int
		command        string
	)

	switch v := img.(type) {
	case *image.RGBA:
		imageBytes = v.Pix
		stride = v.Stride
		command = commandEncodeNRGBA
	case *AnimatedImage:
		// Animated WebP.
		frames := v.GetFrames()
		if len(frames) == 0 {
			return errors.New("webp: animated image has no frames")
		}
		firstFrame := frames[0]
		bounds = firstFrame.Bounds()
		nrgba := convertToNRGBA(firstFrame)
		frameSize := nrgba.Stride * bounds.Dy()
		imageBytes = make([]byte, frameSize*len(frames))
		stride = nrgba.Stride
		for i, frame := range frames {
			var nrgbaFrame *image.NRGBA
			if i == 0 {
				nrgbaFrame = nrgba
			} else {
				nrgbaFrame = convertToNRGBA(frame)
			}
			copy(imageBytes[i*frameSize:(i+1)*frameSize], nrgbaFrame.Pix)
		}
		frameDurations = v.GetFrameDurations()
		loopCount = v.loopCount

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Validate the source animation (open it in a browser / ffprobe); re-export it from the original tool.
  2. Re-encode the source with a standard tool (ffmpeg, gifsicle, avifenc) before adding it to the site.
  3. If a browser-valid animation triggers this, report it to Hugo with the file — it points to a decode-side bug.
Defensive patterns

Strategy: validation

Validate before calling

if animated && frameCount == 0 {
    return fmt.Errorf("animated source %s has no frames", path)
}

Prevention

When it happens

Trigger: Converting an animated source (animated AVIF/GIF decoded into Hugo's AnimatedImage) to WebP when the decoded frame list is empty — typically a corrupt or zero-frame source animation, or an upstream decode that populated frame durations but no pixel frames.

Common situations: Corrupt or truncated animated GIF/AVIF assets fed through .Process "webp"; exotic animations from online converters that declare animation metadata with no actual frames; upstream decoder bugs after format edge cases.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/a83a236f57b62ea3.json. Report an issue: GitHub ↗.