fix(engine): apply the metadata choice to WebP Quick Export (#11058)

This commit is contained in:
Dylan M. Taylor authored and GitHub committed 2026-11-11 16:24:44 -05:00
1 parent d51e4bce94
commit e4efca36aa
2 files changed
+25 -1

No files matched your search

+6 -1
View File
@@ -114,7 +114,12 @@ pub(super) fn quick_export(s: &mut Session, p: &Value) -> Result<Value> {
// WebP uses the regular exporter. Its optional quality is in the Photoshop-style
// 0–12 save scale: invert that mapping so the codec receives the chosen 1–100.
// Keeping quality absent preserves the historical lossless Quick Export behavior.
let (wdoc, _, _) = web_document(&doc, &json!({}), &WebSettings { convert_to_srgb: prefs.convert_to_srgb, ..Default::default() })?;
let st = WebSettings::from_params(&Value::Object(o.clone()), cmd)?;
let (mut wdoc, _, _) = web_document(&doc, &json!({}), &st)?;
// The regular exporter embeds the document's XMP and EXIF as they are: give it only
// what the metadata choice keeps, as the Save for Web formats get.
wdoc.metadata.xmp = web_xmp(&doc, st.metadata).map(std::sync::Arc::from);
wdoc.metadata.exif = web_exif(&doc, st.metadata).map(|e| std::sync::Arc::new(e.to_vec()));
let quality = if prefs.webp_lossless { None } else { Some((f64::from(prefs.webp_quality.clamp(1, 100)) - 1.0) * 12.0 / 99.0) };
let warnings = crate::file_cmds::save_doc(&wdoc, &path, quality)?;
crate::automate_cmds::fire_event(s, "export");
+19
View File
@@ -1396,6 +1396,25 @@ fn embed_color_profile_tags_an_untagged_document_srgb() {
}
}
/// Quick Export as WebP goes through the regular exporter, which embeds a document's XMP and
/// EXIF whole: the export preferences' metadata choice must still apply to it.
#[test]
fn quick_export_webp_keeps_only_the_chosen_metadata() {
let dir = tmp("quick_webp_metadata");
let mut s = session(8);
s.execute("file.fileInfo", json!({"copyright": "© Example", "description": "secret notes"})).unwrap();
let has = |b: &[u8], needle: &[u8]| b.windows(needle.len()).any(|w| w == needle);
for (choice, lossless) in [("none", true), ("copyright", false)] {
s.execute("file.export.exportPreferences", json!({"quickExportFormat": "png", "metadata": choice, "webpLossless": lossless})).unwrap();
let path = format!("{dir}/{choice}.webp");
s.execute("file.export.quickExport", json!({"path": path})).unwrap();
let bytes = std::fs::read(&path).unwrap();
assert!(!has(&bytes, b"secret notes"), "{choice}: the description is not {choice}");
assert_eq!(has(&bytes, b"Example"), choice == "copyright", "{choice}");
}
s.execute("prefs.reset", json!({"path": "export"})).unwrap();
}
/// #5305: `folder` writes the whole image there under the document's own name, so an action
/// recorded with the suggested name saves each document it is played on under that name; it is
/// a destination, never a remembered setting.