{"record":{"id":"7b453110a8cea091","repo":"DioxusLabs/dioxus","slug":"quantization-failed-because-err","errorCode":null,"errorMessage":"Quantization failed, because: {err:?}","messagePattern":"Quantization failed, because: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/opt/image.rs","lineNumber":99,"sourceCode":"    let height = image.height() as usize;\n    let bitmap: Vec<_> = image\n        .into_rgba8()\n        .pixels()\n        .map(|px| imagequant::RGBA::new(px[0], px[1], px[2], px[3]))\n        .collect();\n\n    // Configure the library\n    let mut liq = imagequant::new();\n    liq.set_speed(5).unwrap();\n    liq.set_quality(0, 99).unwrap();\n\n    // Describe the bitmap\n    let mut img = liq.new_image(&bitmap[..], width, height, 0.0).unwrap();\n\n    // The magic happens in quantize()\n    let mut res = match liq.quantize(&mut img) {\n        Ok(res) => res,\n        Err(err) => panic!(\"Quantization failed, because: {err:?}\"),\n    };\n\n    let (palette, pixels) = res.remapped(&mut img).unwrap();\n\n    let file = std::fs::File::create(output_location).unwrap();\n    let w = &mut BufWriter::new(file);\n\n    let mut encoder = png::Encoder::new(w, width as u32, height as u32);\n    encoder.set_color(png::ColorType::Rgba);\n    let mut flattened_palette = Vec::new();\n    let mut alpha_palette = Vec::new();\n    for px in palette {\n        flattened_palette.push(px.r);\n        flattened_palette.push(px.g);\n        flattened_palette.push(px.b);\n        alpha_palette.push(px.a);\n    }\n    encoder.set_palette(flattened_palette);","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/cli/src/opt/image.rs#L81-L117","documentation":"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.","triggerScenarios":"Thrown at packages/cli/src/opt/image.rs:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the underlying image error in the message. Ensure the input image is a supported format and not corrupt, or disable image quantization."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}