{"record":{"id":"887fb5cf0da45023","repo":"getzola/zola","slug":"unable-to-load-this-kind-of-image-with-webp","errorCode":null,"errorMessage":"Unable to load this kind of image with webp","messagePattern":"Unable to load this kind of image with webp","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/imageproc/src/processor.rs","lineNumber":133,"sourceCode":"                let mut encoder = JpegEncoder::new_with_quality(&mut tmp_output_writer, quality);\n                add_color_profile(&mut encoder);\n                encoder.encode_image(&img)?;\n            }\n            Format::WebP { quality } => {\n                // use the `image` builtin encoder for lossless, as it supports color profiles\n                if quality.is_none() && has_color_profile {\n                    let mut encoder = WebPEncoder::new_lossless(&mut tmp_output_writer);\n                    add_color_profile(&mut encoder);\n                    img.write_with_encoder(encoder)?;\n                } else {\n                    if has_color_profile {\n                        log::warn!(\n                            \"processing {}: Lossy WebP encoder does not support color profiles, colors may be incorrect.\",\n                            self.input_path.display()\n                        );\n                    }\n                    let encoder = webp::Encoder::from_image(&img)\n                        .map_err(|_| anyhow!(\"Unable to load this kind of image with webp\"))?;\n                    let memory = match quality {\n                        Some(q) => encoder.encode(q as f32),\n                        None => encoder.encode_lossless(),\n                    };\n                    tmp_output_writer.write_all(memory.as_bytes())?;\n                }\n            }\n            Format::Avif { quality, speed } => {\n                let mut encoder =\n                    AvifEncoder::new_with_speed_quality(&mut tmp_output_writer, speed, quality);\n                add_color_profile(&mut encoder);\n                img.write_with_encoder(encoder)?;\n            }\n        };\n\n        fs::set_permissions(&tmp_output_file, input_permissions)?;\n        fs::rename(&tmp_output_file, &self.output_path)?;\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/imageproc/src/processor.rs#L115-L151","documentation":"When encoding WebP output, the code uses `webp::Encoder::from_image`, which only supports images the underlying webp crate can ingest. If the decoded DynamicImage cannot be converted (an unsupported pixel layout or an internal library failure), the error is mapped to this anyhow message, since encode quality/lossless is then unreachable.","triggerScenarios":"Requesting webp output format for an input image whose decoded representation `webp::Encoder::from_image` cannot accept (unsupported color type / corrupted decode), during `ImageProcessor::perform` with `Format::WebP`.","commonSituations":"Unusual source images (16-bit, exotic color profiles, palette edge cases) routed to webp output; an input that fails to decode properly upstream; older webp crate versions with narrower supported inputs.","solutions":["Convert/re-encode the source image to 8-bit RGBA/RGB (e.g. via PNG) before webp encoding","Choose a different output format (jpeg/png) for that image","Update the webp/image crate dependencies, as newer versions support more input layouts"],"exampleFix":"// before\nformat = \"webp\"  // fails on this 16-bit tiff source\n// after\nlet img = DynamicImage::ImageRgba8(img.to_rgba8()); // force 8-bit RGBA before encoding\nformat = \"webp\"","handlingStrategy":"try-catch","validationCode":"fn webp_encodable(img: &DynamicImage) -> bool {\n    // webp crate accepts 8-bit RGB/RGBA layouts\n    matches!(img, DynamicImage::ImageRgb8(_) | DynamicImage::ImageRgba8(_))\n}\nlet img = DynamicImage::ImageRgba8(img.to_rgba8()); // normalize before encode","typeGuard":"fn is_8bit_rgb_layout(img: &DynamicImage) -> bool {\n    matches!(img.color(), image::ColorType::Rgb8 | image::ColorType::Rgba8)\n}","tryCatchPattern":"let encoder = webp::Encoder::from_image(&img)\n    .map_err(|_| anyhow!(\"Unable to load this kind of image with webp\"))\n    .or_else(|_| {\n        log::warn!(\"falling back to re-encoded RGBA for webp output\");\n        webp::Encoder::from_image(&DynamicImage::ImageRgba8(img.to_rgba8()))\n    })?;","preventionTips":["Normalize decoded images to 8-bit RGBA before requesting webp output","Prefer a different output format for exotic sources (16-bit TIFF, CMYK JPEG)","Keep the webp/image crates updated for broader input support","Log the input path and color type when webp encoding fails to diagnose recurrence"],"tags":["image-processing","webp","encoding"],"backgroundTag":"unsupported-image-format","analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}