mudler/LocalAI · error
Failed to load input image from '%s'\n
Error message
Failed to load input image from '%s'\n
What it means
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.
Source
Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:841
int height = p->height;
// Handle input image for img2img
bool has_input_image = (src_image != NULL && strlen(src_image) > 0);
bool has_mask_image = (mask_image != NULL && strlen(mask_image) > 0);
uint8_t* input_image_buffer = NULL;
uint8_t* mask_image_buffer = NULL;
std::vector<uint8_t> default_mask_image_vec;
if (has_input_image) {
fprintf(stderr, "Loading input image: %s\n", src_image);
int c = 0;
int img_width = 0;
int img_height = 0;
input_image_buffer = stbi_load(src_image, &img_width, &img_height, &c, 3);
if (input_image_buffer == NULL) {
fprintf(stderr, "Failed to load input image from '%s'\n", src_image);
return 1;
}
if (c < 3) {
fprintf(stderr, "Input image must have at least 3 channels, got %d\n", c);
free(input_image_buffer);
return 1;
}
// Resize input image if dimensions don't match
if (img_width != width || img_height != height) {
fprintf(stderr, "Resizing input image from %dx%d to %dx%d\n", img_width, img_height, width, height);
uint8_t* resized_image_buffer = (uint8_t*)malloc(height * width * 3);
if (resized_image_buffer == NULL) {
fprintf(stderr, "Failed to allocate memory for resized image\n");
free(input_image_buffer);
return 1;
}View on GitHub (pinned to 44413a9d06)
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
Example fix
# before curl -F image=@photo.webp .../img2img # stbi_load fails # after (convert first) magick photo.webp photo.png curl -F image=@photo.png .../img2img
Defensive patterns
Strategy: validation
Validate before calling
// Go caller: decode header before invoking img2img
f, err := os.Open(srcPath)
if err != nil { return err }
_, format, err := image.DecodeConfig(f)
f.Close()
if err != nil { return fmt.Errorf("unsupported/corrupt image: %w", err) }
switch format {
case "jpeg", "png":
default:
return fmt.Errorf("format %s not supported by backend; convert to png/jpeg", format)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Clients uploading webp straight from phones/browsers; paths with wrong permissions inside containers; partially transferred files.
Related errors
- Input image must have at least 3 channels, got %d\n
- Failed to allocate memory for resized image\n
- Embedding directory does not exist or is not a directory: %s
- LoRA directory does not exist or is not a directory: %s\n
- LoRA directory not set, cannot parse LoRAs from prompt\n
AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15).
Data as JSON: /api/errors/109b8c695af7613d.
Report an issue: GitHub.