getzola/zola · error

Unable to load this kind of image with webp

Error message

Unable to load this kind of image with webp

What it means

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.

Source

Thrown at components/imageproc/src/processor.rs:133

                let mut encoder = JpegEncoder::new_with_quality(&mut tmp_output_writer, quality);
                add_color_profile(&mut encoder);
                encoder.encode_image(&img)?;
            }
            Format::WebP { quality } => {
                // use the `image` builtin encoder for lossless, as it supports color profiles
                if quality.is_none() && has_color_profile {
                    let mut encoder = WebPEncoder::new_lossless(&mut tmp_output_writer);
                    add_color_profile(&mut encoder);
                    img.write_with_encoder(encoder)?;
                } else {
                    if has_color_profile {
                        log::warn!(
                            "processing {}: Lossy WebP encoder does not support color profiles, colors may be incorrect.",
                            self.input_path.display()
                        );
                    }
                    let encoder = webp::Encoder::from_image(&img)
                        .map_err(|_| anyhow!("Unable to load this kind of image with webp"))?;
                    let memory = match quality {
                        Some(q) => encoder.encode(q as f32),
                        None => encoder.encode_lossless(),
                    };
                    tmp_output_writer.write_all(memory.as_bytes())?;
                }
            }
            Format::Avif { quality, speed } => {
                let mut encoder =
                    AvifEncoder::new_with_speed_quality(&mut tmp_output_writer, speed, quality);
                add_color_profile(&mut encoder);
                img.write_with_encoder(encoder)?;
            }
        };

        fs::set_permissions(&tmp_output_file, input_permissions)?;
        fs::rename(&tmp_output_file, &self.output_path)?;

View on GitHub (pinned to 61d3082821)

Solutions

  1. Convert/re-encode the source image to 8-bit RGBA/RGB (e.g. via PNG) before webp encoding
  2. Choose a different output format (jpeg/png) for that image
  3. Update the webp/image crate dependencies, as newer versions support more input layouts

Example fix

// before
format = "webp"  // fails on this 16-bit tiff source
// after
let img = DynamicImage::ImageRgba8(img.to_rgba8()); // force 8-bit RGBA before encoding
format = "webp"
Defensive patterns

Strategy: try-catch

Validate before calling

fn webp_encodable(img: &DynamicImage) -> bool {
    // webp crate accepts 8-bit RGB/RGBA layouts
    matches!(img, DynamicImage::ImageRgb8(_) | DynamicImage::ImageRgba8(_))
}
let img = DynamicImage::ImageRgba8(img.to_rgba8()); // normalize before encode

Type guard

fn is_8bit_rgb_layout(img: &DynamicImage) -> bool {
    matches!(img.color(), image::ColorType::Rgb8 | image::ColorType::Rgba8)
}

Try / catch

let encoder = webp::Encoder::from_image(&img)
    .map_err(|_| anyhow!("Unable to load this kind of image with webp"))
    .or_else(|_| {
        log::warn!("falling back to re-encoded RGBA for webp output");
        webp::Encoder::from_image(&DynamicImage::ImageRgba8(img.to_rgba8()))
    })?;

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Related errors


AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/887fb5cf0da45023. Report an issue: GitHub.