{"record":{"id":"46be3e8eb1fdce82","repo":"tonhowtf/omniget","slug":"n-o-gravei-o-png","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/image_sprite.rs","lineNumber":300,"sourceCode":"    }\n}\n\nfn ext_of(format: &str) -> &'static str {\n    if format.eq_ignore_ascii_case(\"jpeg\") || format.eq_ignore_ascii_case(\"jpg\") {\n        \"jpg\"\n    } else {\n        \"png\"\n    }\n}\n\nfn write_image(img: &RgbaImage, path: &Path, format: &str, quality: u8) -> anyhow::Result<u64> {\n    let data = if ext_of(format) == \"jpg\" {\n        super::image_compress::encode_jpeg(&DynamicImage::ImageRgba8(img.clone()), quality)?\n    } else {\n        let mut buf = std::io::Cursor::new(Vec::new());\n        DynamicImage::ImageRgba8(img.clone())\n            .write_to(&mut buf, image::ImageFormat::Png)\n            .map_err(|e| anyhow!(\"não gravei o PNG: {}\", e))?;\n        buf.into_inner()\n    };\n    if let Some(parent) = path.parent() {\n        if !parent.as_os_str().is_empty() {\n            std::fs::create_dir_all(parent)?;\n        }\n    }\n    std::fs::write(path, &data)?;\n    Ok(data.len() as u64)\n}\n\n/// JSON de atlas no formato de mapa (o mesmo shape que o TexturePacker usa no\n/// preset \"JSON (Hash)\"), que é o que engine e bundler já sabem ler.\npub fn atlas_json(frames: &[SpriteFrame], sheet: &str, w: u32, h: u32) -> String {\n    let mut map = serde_json::Map::new();\n    for f in frames {\n        map.insert(\n            f.name.clone(),","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/image_sprite.rs#L282-L318","documentation":"Thrown in write_image when encoding a sliced/packed sprite cell (or batch output) to PNG in memory fails. The `image` crate's write_to returned an error, which is wrapped with context naming the failed PNG write.","triggerScenarios":"Calling write_image (via slice, pack, or batch) with a format that is not jpg, where DynamicImage::write_to(.., ImageFormat::Png) fails — typically an unsupported color type/encoding parameters combination, or an out-of-memory allocation for huge buffers.","commonSituations":"Writing very large spritesheets exceeding memory limits; unusual image color formats passed through; disk-full scenarios manifesting as encode/IO errors in downstream fs::write.","solutions":["Check the underlying image::ImageError message in the context string for the exact encoding problem.","Convert the image to a supported color type before writing (e.g. to_rgba8, which this path already applies via ImageRgba8).","Ensure output directories are writable and there is disk space before calling write_image.","If JPEG was intended, confirm the format argument maps to jpg so the encode_jpeg branch is taken."],"exampleFix":"// before\nDynamicImage::ImageRgba8(img.clone())\n    .write_to(&mut buf, image::ImageFormat::Png)\n    .map_err(|e| anyhow!(\"não gravei o PNG: {}\", e))?;\n// after\nlet img = DynamicImage::ImageRgba8(img.clone());\nimg.write_to(&mut buf, image::ImageFormat::Png)\n    .map_err(|e| anyhow!(\"não gravei o PNG: {}\", e))?; // adds explicit rgba8 + logging of the error chain","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match write_image(&img, &path, quality) {\n    Err(e) if format!(\"{e}\").contains(\"não gravei o PNG\") => {\n        tracing::error!(\"falha ao codificar PNG {}: {e:#}\", path.display());\n        // fallback: escrever como PNG via codec alternativo ou reportar ao usuário\n    }\n    other => other?,\n}","preventionTips":["Always normalize images to Rgba8 before encoding PNG.","Check free disk space and directory writability before batch writes.","Keep image-crate features enabled for the formats you write.","Log the full error chain to distinguish encode vs fs errors."],"tags":["image-encoding","png","rust","image-crate"],"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"}