{"record":{"id":"a07e698ad4b3e0de","repo":"tonhowtf/omniget","slug":"n-o-gravei-o-png-img-bg","errorCode":null,"errorMessage":"não gravei o PNG {}: {}","messagePattern":"não gravei o PNG (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":359,"sourceCode":"        \"png\"\n    }\n}\n\nfn save_image(img: &DynamicImage, dest: &Path, ext: &str, quality: u8) -> anyhow::Result<u64> {\n    if let Some(parent) = dest.parent() {\n        std::fs::create_dir_all(parent).with_context(|| format!(\"criando {}\", parent.display()))?;\n    }\n    if ext == \"jpg\" {\n        let file =\n            std::fs::File::create(dest).with_context(|| format!(\"criando {}\", dest.display()))?;\n        let mut w = std::io::BufWriter::new(file);\n        let mut enc =\n            image::codecs::jpeg::JpegEncoder::new_with_quality(&mut w, quality.clamp(1, 100));\n        enc.encode_image(&img.to_rgb8())\n            .map_err(|e| anyhow!(\"não gravei o JPEG {}: {}\", dest.display(), e))?;\n    } else {\n        img.save_with_format(dest, image::ImageFormat::Png)\n            .map_err(|e| anyhow!(\"não gravei o PNG {}: {}\", dest.display(), e))?;\n    }\n    Ok(std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0))\n}\n\n// ── Execução ───────────────────────────────────────────────────────────\n\n/// Roda a inferência num arquivo já aberto e devolve a máscara no tamanho\n/// original da imagem.\nfn mask_for_image(\n    session: &mut ort::session::Session,\n    img: &DynamicImage,\n    p: &BgParams,\n) -> anyhow::Result<GrayImage> {\n    let side = p.size as i64;\n    // O `ort` traz um `ndarray` próprio (0.17) e o crate usa o 0.16, então o\n    // tensor atravessa a fronteira como forma + dados contíguos, que é o que o\n    // `Tensor::from_array` aceita sem depender de versão de crate nenhuma.\n    let (data, _) = normalize_input(img, p).into_raw_vec_and_offset();","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L341-L377","documentation":"The PNG branch of `save_image`: if `img.save_with_format(dest, ImageFormat::Png)` fails, the error is wrapped as 'não gravei o PNG {path}: {e}'. It means PNG serialization or file writing of the processed image failed.","triggerScenarios":"Calling `save_image` with a non-JPEG destination where PNG saving fails — disk full, permission denied on the destination, invalid/unwritable path, or image dimensions exceeding PNG encoder limits.","commonSituations":"Saving into a read-only directory or one deleted mid-run; extremely large stitched images hitting encoder limits; destination filename with illegal characters on the platform.","solutions":["Inspect the wrapped image::ImageError/IO error: fix disk space or permissions on the destination path.","Ensure the destination directory exists and the filename is valid for the OS (no reserved characters).","For very large images, cap dimensions (e.g. via cap_width) or switch to JPEG output before retrying."],"exampleFix":"// before\nlet dest = Path::new(\"/only-readable/out.png\");\nsave_image(&img, dest, 90)?; // não gravei o PNG ...\n// after\nlet dest = home_dir().join(\"Pictures\").join(\"omniget-out.png\");\nstd::fs::create_dir_all(dest.parent().unwrap())?;\nsave_image(&img, &dest, 90)?;","handlingStrategy":"try-catch","validationCode":"let dir = dest.parent().unwrap();\nif !dir.is_dir() { std::fs::create_dir_all(dir)?; }\nlet probe = dir.join(\".write_probe\");\nstd::fs::write(&probe, b\"\").map_err(|e| format!(\"destino sem permissão: {e}\"))?\n;let _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"if let Err(e) = save_image(&img, dest, quality) {\n    if e.to_string().contains(\"não gravei o PNG\") {\n        eprintln!(\"falha ao escrever PNG em {}: {e:#}\", dest.display());\n        // retry with reduced dimensions or alternate path\n    }\n}","preventionTips":["Create the destination directory before saving","Validate the filename for platform-illegal characters","Cap very large image dimensions before PNG save","Write to temp file and rename for atomicity"],"tags":["file-io","png","image-encoding","rust"],"backgroundTag":"file-write-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}