{"record":{"id":"109b8c695af7613d","repo":"mudler/LocalAI","slug":"failed-to-load-input-image-from-s-n","errorCode":null,"errorMessage":"Failed to load input image from '%s'\\n","messagePattern":"Failed to load input image from '(.+?)'\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":841,"sourceCode":"    int height = p->height;\n\n    // Handle input image for img2img\n    bool has_input_image = (src_image != NULL && strlen(src_image) > 0);\n    bool has_mask_image = (mask_image != NULL && strlen(mask_image) > 0);\n\n    uint8_t* input_image_buffer = NULL;\n    uint8_t* mask_image_buffer = NULL;\n    std::vector<uint8_t> default_mask_image_vec;\n\n    if (has_input_image) {\n        fprintf(stderr, \"Loading input image: %s\\n\", src_image);\n\n        int c = 0;\n        int img_width = 0;\n        int img_height = 0;\n        input_image_buffer = stbi_load(src_image, &img_width, &img_height, &c, 3);\n        if (input_image_buffer == NULL) {\n            fprintf(stderr, \"Failed to load input image from '%s'\\n\", src_image);\n            return 1;\n        }\n        if (c < 3) {\n            fprintf(stderr, \"Input image must have at least 3 channels, got %d\\n\", c);\n            free(input_image_buffer);\n            return 1;\n        }\n\n        // Resize input image if dimensions don't match\n        if (img_width != width || img_height != height) {\n            fprintf(stderr, \"Resizing input image from %dx%d to %dx%d\\n\", img_width, img_height, width, height);\n\n            uint8_t* resized_image_buffer = (uint8_t*)malloc(height * width * 3);\n            if (resized_image_buffer == NULL) {\n                fprintf(stderr, \"Failed to allocate memory for resized image\\n\");\n                free(input_image_buffer);\n                return 1;\n            }","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L823-L859","documentation":"Hard error in the img2img/inpainting path: stbi_load() returned NULL for the source image, so generation aborts with return code 1 before any model work. stb_image supports JPEG/PNG/BMP/PSD/TGA/GIF/HDR/PIC; unsupported formats (e.g. webp, heic, tiff in some builds), missing files, and corrupt files all produce NULL.","triggerScenarios":"Calling the img2img entry point with src_image pointing at a nonexistent path, a file stb_image cannot decode (webp/heic), or a truncated/corrupt image; also 0-byte files after failed uploads.","commonSituations":"Clients uploading webp straight from phones/browsers; paths with wrong permissions inside containers; partially transferred files.","solutions":["Confirm the file exists at src_image and is readable by the backend process","Convert the image to PNG or JPEG (stb-supported formats) before sending","If the file exists but fails, verify it opens in an image viewer and re-export"],"exampleFix":"# before\ncurl -F image=@photo.webp .../img2img  # stbi_load fails\n\n# after (convert first)\nmagick photo.webp photo.png\ncurl -F image=@photo.png .../img2img","handlingStrategy":"validation","validationCode":"// Go caller: decode header before invoking img2img\nf, err := os.Open(srcPath)\nif err != nil { return err }\n_, format, err := image.DecodeConfig(f)\nf.Close()\nif err != nil { return fmt.Errorf(\"unsupported/corrupt image: %w\", err) }\nswitch format {\ncase \"jpeg\", \"png\":\ndefault:\n    return fmt.Errorf(\"format %s not supported by backend; convert to png/jpeg\", format)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert webp/heic/tiff uploads to PNG server-side before passing the path to the backend","Check file existence and readability first — the backend only reports a generic failure"],"tags":["stablediffusion","img2img","image-loading","stb"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}