tonhowtf/omniget · error

não abri a imagem

Error message

não abri a imagem: {}

What it means

Open failure in compress_one: the input file could not be opened or decoded by the image crate — wrong path, unreadable file, or unsupported/corrupt image format — so this item is marked failed instead of compressed.

Solutions

  1. Confirm the file path is correct and readable
  2. Convert the image to a supported format (JPEG/PNG/WebP) before batch compression
  3. Skip the corrupt file and continue with the rest of the batch
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src-tauri/omniget-core/src/core/tools/image_compress.rs:136 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/a06db5ba53cc2703. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/image_compress.rs:136

    let scale = max_side as f32 / img.width().max(img.height()) as f32;
    img.resize(
        ((img.width() as f32 * scale).round() as u32).max(1),
        ((img.height() as f32 * scale).round() as u32).max(1),
        FilterType::Lanczos3,
    )
}

fn flatten(img: &DynamicImage, hex: &str) -> DynamicImage {
    let bg = super::icon_pack::parse_hex(hex);
    let mut canvas = image::RgbaImage::from_pixel(img.width(), img.height(), bg);
    image::imageops::overlay(&mut canvas, &img.to_rgba8(), 0, 0);
    DynamicImage::ImageRgba8(canvas)
}

fn compress_one(opts: &CompressOptions, input: &str) -> anyhow::Result<CompressItem> {
    let inp = Path::new(input);
    let bytes_before = std::fs::metadata(inp).map(|m| m.len()).unwrap_or(0);
    let mut img = image::open(inp).map_err(|e| anyhow!("não abri a imagem: {}", e))?;
    if img.color().has_alpha() {
        img = flatten(&img, &opts.background);
    }
    img = resize_to_side(&img, opts.max_side);
    let mut scaled = opts.max_side > 0 && img.width().max(img.height()) == opts.max_side;

    let (data, quality, hit) = if opts.target_kb > 0 {
        let target = opts.target_kb * 1024;
        let (mut data, mut quality, mut fits) = fit_quality(&img, target, 40, 95)?;
        // Nem no melhor caso coube: cede qualidade e depois vai encolhendo.
        // Foto ruidosa precisa de muitas rodadas; parar em três deixava o
        // usuário com um arquivo acima do alvo e nenhuma explicação.
        let mut tries = 0;
        while !fits && tries < 8 {
            let floor = if tries < 2 { 30 } else { 20 };
            let side = (img.width().max(img.height()) as f32 * 0.8).round() as u32;
            if side < 200 {
                break;

View on GitHub (pinned to 8600b91f42)