tonhowtf/omniget · error
não gravei o PNG
Error message
não gravei o PNG {}: {} What it means
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.
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.
Example fix
// before
let dest = Path::new("/only-readable/out.png");
save_image(&img, dest, 90)?; // não gravei o PNG ...
// after
let dest = home_dir().join("Pictures").join("omniget-out.png");
std::fs::create_dir_all(dest.parent().unwrap())?;
save_image(&img, &dest, 90)?; Defensive patterns
Strategy: try-catch
Validate before calling
let dir = dest.parent().unwrap();
if !dir.is_dir() { std::fs::create_dir_all(dir)?; }
let probe = dir.join(".write_probe");
std::fs::write(&probe, b"").map_err(|e| format!("destino sem permissão: {e}"))?
;let _ = std::fs::remove_file(&probe); Try / catch
if let Err(e) = save_image(&img, dest, quality) {
if e.to_string().contains("não gravei o PNG") {
eprintln!("falha ao escrever PNG em {}: {e:#}", dest.display());
// retry with reduced dimensions or alternate path
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/a07e698ad4b3e0de.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/img_bg.rs:359
"png"
}
}
fn save_image(img: &DynamicImage, dest: &Path, ext: &str, quality: u8) -> anyhow::Result<u64> {
if let Some(parent) = dest.parent() {
std::fs::create_dir_all(parent).with_context(|| format!("criando {}", parent.display()))?;
}
if ext == "jpg" {
let file =
std::fs::File::create(dest).with_context(|| format!("criando {}", dest.display()))?;
let mut w = std::io::BufWriter::new(file);
let mut enc =
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut w, quality.clamp(1, 100));
enc.encode_image(&img.to_rgb8())
.map_err(|e| anyhow!("não gravei o JPEG {}: {}", dest.display(), e))?;
} else {
img.save_with_format(dest, image::ImageFormat::Png)
.map_err(|e| anyhow!("não gravei o PNG {}: {}", dest.display(), e))?;
}
Ok(std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0))
}
// ── Execução ───────────────────────────────────────────────────────────
/// Roda a inferência num arquivo já aberto e devolve a máscara no tamanho
/// original da imagem.
fn mask_for_image(
session: &mut ort::session::Session,
img: &DynamicImage,
p: &BgParams,
) -> anyhow::Result<GrayImage> {
let side = p.size as i64;
// O `ort` traz um `ndarray` próprio (0.17) e o crate usa o 0.16, então o
// tensor atravessa a fronteira como forma + dados contíguos, que é o que o
// `Tensor::from_array` aceita sem depender de versão de crate nenhuma.
let (data, _) = normalize_input(img, p).into_raw_vec_and_offset();View on GitHub (pinned to 8600b91f42)