diff --git a/crates/ui-egui/src/export_dialog.rs b/crates/ui-egui/src/export_dialog.rs index e88d6c3a89..5897132c2d 100644 --- a/crates/ui-egui/src/export_dialog.rs +++ b/crates/ui-egui/src/export_dialog.rs @@ -74,16 +74,19 @@ fn n(f: &Map, k: &str, d: f64) -> f64 { fn export_document(doc: &Document, f: &Map, max_side: Option) -> Result { let mut s = photocraft_engine::Session::new(); s.add_document(doc.clone(), None); - let scale = n(f, "scale", 100.0) / 100.0; - let mut w = (doc.size.width as f64 * scale).round().max(1.0); + let mut scale = n(f, "scale", 100.0) / 100.0; if let Some(m) = max_side { let long = doc.size.width.max(doc.size.height) as f64 * scale; if long > m as f64 { - w = (w * m as f64 / long).round().max(1.0); + scale *= m as f64 / long; } } - if (w - doc.size.width as f64).abs() >= 1.0 { - s.execute("image.imageSize", json!({"width": w, "resample": if max_side.is_some() { "bilinear" } else { "bicubic" }})).map_err(|e| e.to_string())?; + // Both dimensions are sent: a scale can leave a 1 px width unchanged while halving the + // height, and the engine would otherwise keep the aspect ratio from the width alone. + let (w, h) = scaled_size(doc.size.width as f64, doc.size.height as f64, scale); + if (w - doc.size.width as f64).abs() >= 1.0 || (h - doc.size.height as f64).abs() >= 1.0 { + s.execute("image.imageSize", json!({"width": w, "height": h, "resample": if max_side.is_some() { "bilinear" } else { "bicubic" }})) + .map_err(|e| e.to_string())?; } let fmt = s_fmt(f); if !f.get("transparency").and_then(Value::as_bool).unwrap_or(true) || fmt == "jpg" { @@ -92,6 +95,12 @@ fn export_document(doc: &Document, f: &Map, max_side: Option s.active().map(|d| (*d.doc).clone()).ok_or_else(|| "export failed".into()) } +/// The exported pixel size: each side scaled and rounded on its own, never below 1 px. The +/// dialog's size label and `export_document` share it so the label names the file's real size. +fn scaled_size(w: f64, h: f64, scale: f64) -> (f64, f64) { + ((w * scale).round().max(1.0), (h * scale).round().max(1.0)) +} + /// Export As already supports lossy WebP; reuse the Quick Export defaults when /// choosing that format so both flows expose the same quality and lossless options. fn set_format_defaults(f: &mut Map, fmt: &str, prefs: &photocraft_engine::prefs::Export) { @@ -188,8 +197,8 @@ pub fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map