{"id":"8e937ad1d71f2e5f","repo":"gohugoio/hugo","slug":"webp-image-is-too-large-to-encode","errorCode":null,"errorMessage":"webp: image is too large to encode","messagePattern":"webp: image is too large to encode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/webp.go","lineNumber":242,"sourceCode":"\t\t\tSource: bytes.NewReader(b),\n\t\t},\n\t}\n\n\tout, err := dd.Execute(context.Background(), message)\n\tif err != nil {\n\t\treturn image.Config{}, err\n\t}\n\treturn image.Config{\n\t\tWidth:      out.Data.Params.Width,\n\t\tHeight:     out.Data.Params.Height,\n\t\tColorModel: color.RGBAModel,\n\t}, nil\n}\n\nfunc (d *WebpCodec) Encode(w io.Writer, img image.Image, opts map[string]any) error {\n\tb := img.Bounds()\n\tif b.Dx() >= 1<<16 || b.Dy() >= 1<<16 {\n\t\treturn errors.New(\"webp: image is too large to encode\")\n\t}\n\n\tdd, err := d.d()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tconst (\n\t\tcommandEncodeNRGBA = \"encodeNRGBA\"\n\t\tcommandEncodeGray  = \"encodeGray\"\n\t)\n\n\tvar (\n\t\tbounds         = img.Bounds()\n\t\timageBytes     []byte\n\t\tstride         int\n\t\tframeDurations []int\n\t\tloopCount      int","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/warpc/webp.go#L224-L260","documentation":"Returned by WebpCodec.Encode (internal/warpc/webp.go:241-242) before dispatching to the WASM libwebp encoder. The WebP format itself caps dimensions at 16383×16383, and Hugo rejects anything with a width or height of 65536+ up front (with libwebp enforcing the tighter limit); the check fails fast instead of letting the encoder produce a broken file.","triggerScenarios":"Encoding an image to WebP via Hugo's image processing (.Resize/.Process/.Fill with target format webp, or images.Config webp output) where the source or target bounds have Dx() or Dy() ≥ 65536 — e.g. converting an enormous panorama or a giant sprite sheet.","commonSituations":"Huge scanned images, stitched panoramas, or map tiles converted to WebP; automated pipelines that pass original camera/scan resolution straight into WebP output; accidentally multiplying dimensions in a resize spec (e.g. \"x\" filter args swapped).","solutions":["Resize the image below the WebP limit before/while converting: {{ $img := $img.Resize \"16000x webp\" }} (WebP's real cap is 16383 per side).","Keep oversized assets in a format without the limit (PNG/JPEG/AVIF) instead of WebP.","Check your resize arguments for typos producing absurd target dimensions."],"exampleFix":"// before (layouts/page.html)\n{{ $out := $huge.Process \"webp\" }}\n// after\n{{ $out := $huge.Process \"resize 16000x webp\" }}","handlingStrategy":"validation","validationCode":"const webpMax = 16383 // WebP hard limit per dimension\nif cfg.Width > webpMax || cfg.Height > webpMax {\n    // resize first or choose another target format\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check dimensions against WebP's 16383px per-side limit before requesting webp output","Resize oversized images earlier in the pipeline (images.Resize) before format conversion","Fall back to jpeg/png output only if the user explicitly allows a different format"],"tags":["hugo","webp","image-processing","limits","encode"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}