gohugoio/hugo · error
WebPPictureInit failed\n
Error message
WebPPictureInit failed\n
What it means
Printed by genwebp's encodeNRGBA (webp.c:117) when WebPPictureInit(&pic) returns false. WebPPictureInit zeroes and sets up a WebPPicture struct and should essentially never fail in a correctly built libwebp; failure indicates an ABI mismatch (the C binary was built against a different libwebp header version than the shared library it loaded), a corrupted WebPPicture pointer, or a severely memory-starved process. The function returns NULL and the caller surfaces 'Error encoding NRGBA to WebP' to the host.
Source
Thrown at internal/warpc/genwebp/webp.c:117
} InputMessage;
typedef struct
{
Header header;
InputData data;
} OutputMessage;
#define MAX_LINE_LENGTH 4096
static uint8_t *encodeNRGBA(WebPConfig *config, const uint8_t *rgba, int width, int height, int stride, size_t *output_size)
{
WebPPicture pic;
WebPMemoryWriter wrt;
int ok;
if (!WebPPictureInit(&pic))
{
fprintf(stderr, "WebPPictureInit failed\n");
return NULL;
}
pic.use_argb = 1;
pic.width = width;
pic.height = height;
pic.writer = WebPMemoryWrite;
pic.custom_ptr = &wrt;
WebPMemoryWriterInit(&wrt);
ok = WebPPictureImportRGBA(&pic, rgba, stride);
if (ok)
{
ok = WebPEncode(config, &pic);
if (!ok)
{
fprintf(stderr, "WebPEncode failed: %d (%s)\n", pic.error_code, kErrorMessages[pic.error_code]);
}
}View on GitHub (pinned to 52c9bd7908)
Solutions
- Rebuild the Hugo binary (and its bundled genwebp) from source against the libwebp now present at runtime, or pin libwebp to the version Hugo was built with.
- Run `ldd` on the genwebp executable to confirm which libwebp it resolves and that the path matches the build-time expectation.
- If shipping a static build, ensure libwebp is statically linked to remove the runtime mismatch class entirely.
- In containers, pin the libwebp package version and rebuild the image when bumping it.
- Free memory / raise cgroup limits if the box is genuinely OOM.
Example fix
# before: system libwebp updated, Hugo's bundled worker now mismatches $ hugo build # WebPPictureInit failed at runtime # after: rebuild genwebp against the current libwebp, or link statically go build -tags netgo -ldflags '-linkmode external' ./... # or in the Hugo Makefile / build script: CGO_LDFLAGS="-static" go build
Defensive patterns
Strategy: validation
Validate before calling
// In the host: verify the genwebp binary resolves the expected libwebp before use.
func checkLibwebp(ctx context.Context, bin string) error {
out, err := exec.CommandContext(ctx, "ldd", bin).CombinedOutput()
if err != nil { return err }
if !bytes.Contains(out, []byte("libwebp")) {
return fmt.Errorf("genwebp does not link libwebp as expected")
}
return nil
} Prevention
- Ship genwebp with libwebp statically linked to remove the runtime-mismatch class.
- Pin the libwebp package version in deployment images and rebuild when bumping.
- Run `ldd` on the worker binary in CI to assert the resolved libwebp path.
- Treat WebPPictureInit failure as fatal and surface a clear error rather than retrying on the same binary.
When it happens
Trigger: genwebp was built/linked against one libwebp version but at runtime resolves a different version (e.g. system libwebp updated underneath the Hugo binary), the WebPPicture struct layout differs between compile-time headers and runtime library, or memory allocation inside libwebp failed during init.
Common situations: Hugo binary moved between machines with incompatible libwebp, a distro upgrade replaced libwebp without rebuilding Hugo's C workers, dynamic linking picks up LD_LIBRARY_PATH override, or a container image layered an incompatible libwebp on top of the Hugo base image.
Related errors
- WebPEncode failed: %d (%s)\n
- WebPAnimEncoderAssemble failed\n
- WebPPictureImportRGBA failed: %d (%s)\n
- Error creating WebPAnimEncoder\n
- WebPPictureImportRGBA failed\n
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/df5a9ebb639a9209.
Report an issue: GitHub.