Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Batch Same format: an input without an extension is saved as PNG

Higgs32584b3bee7496e84
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index cee41b934..eb3f80016 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -1095,13 +1095,26 @@ pub(crate) fn process_tree(inputs: &[BatchInput], output: &str, format: &str, sa
/// The extension a batch output takes with Format "Same": the input's own, except for formats
/// PhotoCraft opens but can't write, camera raws above all (#5799: a folder of ARWs failed on
-/// every file). Those are saved as PSD, the format Photoshop's Save As offers for a raw.
+/// every file). Those are saved as PSD, the format Photoshop's Save As offers for a raw. An input
+/// whose file name has no extension (a dot in a folder name doesn't count) is saved as PNG.
fn same_format(path: &str) -> String {
const IMPORT_ONLY: &[&str] = &["pdn", "kra", "krz", "af", "afdesign", "afphoto", "afpub"];
- let ext = path.rsplit('.').next().unwrap_or("png").to_ascii_lowercase();
+ let ext = extension(path).unwrap_or_else(|| "png".into());
if photocraft_io::raw::EXTENSIONS.contains(&ext.as_str()) || IMPORT_ONLY.contains(&ext.as_str()) { "psd".into() } else { ext }
}
+#[cfg(test)]
+#[test]
+fn same_format_takes_the_file_names_extension() {
+ assert_eq!(same_format("/in/a.PNG"), "png");
+ assert_eq!(same_format("/in/IMG_0001.ARW"), "psd");
+ assert_eq!(same_format("/in/a.kra"), "psd");
+ // No extension in the file name: PNG, not the path after a dot in a folder name.
+ assert_eq!(same_format("/in/v1.2/scan"), "png");
+ assert_eq!(same_format("C:\\in.d\\scan"), "png");
+ assert_eq!(same_format("/in/.hidden"), "png");
+}
+
fn process_outputs<'a>(outputs: impl IntoIterator<Item = (&'a str, String)>, save: SaveOpts, f: &dyn Fn(&mut Session) -> Result<()>) -> Value {
let mut files = Vec::new();
let mut errors = Vec::new();