DioxusLabs/dioxus · error
Quantization failed, because: {err:?}
Error message
Quantization failed, because: {err:?} What it means
The imagequant library returned an error when quantizing the RGBA bitmap during PNG compression in the CLI's asset pipeline. This usually means the input image was invalid (zero width/height or unreadable pixel data) after earlier setup calls had already been unwrapped.
Source
Thrown at packages/cli/src/opt/image.rs:99
let height = image.height() as usize;
let bitmap: Vec<_> = image
.into_rgba8()
.pixels()
.map(|px| imagequant::RGBA::new(px[0], px[1], px[2], px[3]))
.collect();
// Configure the library
let mut liq = imagequant::new();
liq.set_speed(5).unwrap();
liq.set_quality(0, 99).unwrap();
// Describe the bitmap
let mut img = liq.new_image(&bitmap[..], width, height, 0.0).unwrap();
// The magic happens in quantize()
let mut res = match liq.quantize(&mut img) {
Ok(res) => res,
Err(err) => panic!("Quantization failed, because: {err:?}"),
};
let (palette, pixels) = res.remapped(&mut img).unwrap();
let file = std::fs::File::create(output_location).unwrap();
let w = &mut BufWriter::new(file);
let mut encoder = png::Encoder::new(w, width as u32, height as u32);
encoder.set_color(png::ColorType::Rgba);
let mut flattened_palette = Vec::new();
let mut alpha_palette = Vec::new();
for px in palette {
flattened_palette.push(px.r);
flattened_palette.push(px.g);
flattened_palette.push(px.b);
alpha_palette.push(px.a);
}
encoder.set_palette(flattened_palette);View on GitHub (pinned to 24f6a829df)
Solutions
- Inspect the underlying image error in the message. Ensure the input image is a supported format and not corrupt, or disable image quantization.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at packages/cli/src/opt/image.rs:99 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23).
Data as JSON: /api/errors/7b453110a8cea091.
Report an issue: GitHub.