gohugoio/hugo · error

webp: image is too large to encode

Error message

webp: image is too large to encode

What it means

Returned by WebpCodec.Encode in internal/warpc/webp.go:242 when either image dimension (Dx or Dy of the bounds) is >= 65536 (1<<16). WebP's format limit is 16383 per axis in libwebp and the codec rejects anything at/above 2^16 outright before dispatching to WASM.

Solutions

  1. Resize/downsample the image so both dimensions stay well under 65536 (preferably <= 16383, libwebp's practical max).
  2. Switch the output format to JPEG/PNG for ultra-large images that legitimately need huge dimensions.
  3. Check the source pipeline for an accidental upscale (e.g. a "Resize 99999x" typo).

Example fix

// before
{{ $webp = $hugeImg.Resize "70000x webp" }}
// after
{{ $webp = $hugeImg.Resize "1600x webp" }}
Defensive patterns

Strategy: validation

Validate before calling

// Reject oversized images before webp encode.
b := img.Bounds()
if b.Dx() >= 1<<16 || b.Dy() >= 1<<16 {
    return fmt.Errorf("image %dx%d too large for webp", b.Dx(), b.Dy())
}

Prevention

When it happens

Trigger: Calling webp encode (|webp or resources with webp output) on an image whose width or height is 65536 pixels or more. The check runs locally before any WASM call.

Common situations: A huge hero/panorama image, an accidentally upsampled image, or a stitched sprite atlas exceeding the dimension cap.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/8e937ad1d71f2e5f. Report an issue: GitHub.

Appendix: source

Thrown at internal/warpc/webp.go:242

			Source: bytes.NewReader(b),
		},
	}

	out, err := dd.Execute(context.Background(), message)
	if err != nil {
		return image.Config{}, err
	}
	return image.Config{
		Width:      out.Data.Params.Width,
		Height:     out.Data.Params.Height,
		ColorModel: color.RGBAModel,
	}, nil
}

func (d *WebpCodec) Encode(w io.Writer, img image.Image, opts map[string]any) error {
	b := img.Bounds()
	if b.Dx() >= 1<<16 || b.Dy() >= 1<<16 {
		return errors.New("webp: image is too large to encode")
	}

	dd, err := d.d()
	if err != nil {
		return err
	}

	const (
		commandEncodeNRGBA = "encodeNRGBA"
		commandEncodeGray  = "encodeGray"
	)

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

View on GitHub (pinned to 52c9bd7908)