Skip to content

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

fix(atn): write WebP saves with Photoshop's built-in WebP class

Jason White5f0b8cb51ce0
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs
index d6f04fce8..bb1cfe075 100644
--- a/crates/engine/src/atn_cmds.rs
+++ b/crates/engine/src/atn_cmds.rs
@@ -1550,13 +1550,16 @@ fn open_to(_: &str, p: &Value) -> Option<Descriptor> {
}
/// Save As format classes (`As`) and the extensions PhotoCraft saves them under. The first
-/// extension of a class is the one exported; WebP comes from Google's WebPShop plug-in.
+/// extension of a class is the one exported, and the first class of an extension is the one
+/// written back. `WebPFormat` is Photoshop's built-in WebP (checked against Photoshop 2026); the
+/// Google classes come from the older WebPShop plug-in and are only read.
const SAVE_FORMATS: &[(&str, &[&str])] = &[
("Pht3", &["psd"]),
("PNGF", &["png"]),
("JPEG", &["jpg", "jpeg"]),
("TIFF", &["tif", "tiff"]),
("BMPF", &["bmp"]),
+ ("WebPFormat", &["webp"]),
("Google WebPShop", &["webp"]),
("Google WebP", &["webp"]),
];
diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs
index c85fdabb9..3148dadc6 100644
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@ -1423,6 +1423,7 @@ fn save_as_to_a_file_imports_with_its_destination() {
item("save", "Save", Some(save_as("PNGF", "/out/result.png"))),
item("save", "Save", Some(save_as("Google WebPShop", "C:\\out\\result.webp").with("Cpy ", D::Boolean(true)))),
item("save", "Save", Some(save_as("JPEG", "/out/result.jpeg"))),
+ item("save", "Save", Some(save_as("WebPFormat", "/out/result.webp"))),
item("save", "Save", None),
item("save", "Save", Some(desc("null").with("DocI", long(53.0)))),
]);
@@ -1433,6 +1434,7 @@ fn save_as_to_a_file_imports_with_its_destination() {
("file.saveAs".to_string(), json!({"path": "/out/result.png"})),
("file.saveACopy".to_string(), json!({"path": "C:\\out\\result.webp"})),
("file.saveAs".to_string(), json!({"path": "/out/result.jpeg"})),
+ ("file.saveAs".to_string(), json!({"path": "/out/result.webp"})),
("file.save".to_string(), json!({})),
("file.save".to_string(), json!({})),
]
@@ -1482,6 +1484,8 @@ fn saves_round_trip_through_photoshop_events() {
assert_eq!(get_obj(first, "As ").map(|f| trimmed(&f.class_id)).as_deref(), Some("Pht3"));
assert_eq!(first.get("In ").and_then(path_text).as_deref(), Some("/out/result.psd"));
assert_eq!(get_bool(items[1].descriptor.as_ref().unwrap(), "Cpy "), Some(true));
+ // Photoshop's own WebP class, not the plug-in's: Photoshop 2026 rejects `Google WebPShop`.
+ assert_eq!(get_obj(items[1].descriptor.as_ref().unwrap(), "As ").map(|f| trimmed(&f.class_id)).as_deref(), Some("WebPFormat"));
assert_eq!(import(&bytes).unwrap().actions[0].steps, steps);
// A Save As PhotoCraft can't express in Photoshop's terms is skipped, never exported as a