From 3c9e9366534187cd880ad5a975a411ce443a42fe Mon Sep 17 00:00:00 2001 From: Kanyin Cai Date: Sat, 21 Mar 2026 13:47:38 +0100 Subject: [PATCH] fix(02-01): preserve aspect ratio in fir_resize The old image crate's DynamicImage::resize() fitted within (w, h) bounds while preserving aspect ratio. fir_resize() was resizing to exact dimensions, stretching images to fill the preview panel. --- yazi-adapter/src/image.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/yazi-adapter/src/image.rs b/yazi-adapter/src/image.rs index abac7d09..8a67663b 100644 --- a/yazi-adapter/src/image.rs +++ b/yazi-adapter/src/image.rs @@ -101,6 +101,13 @@ impl Image { } fn fir_resize(img: DynamicImage, w: u32, h: u32, alg: ResizeAlg) -> anyhow::Result { + // Preserve aspect ratio: fit within (w, h) bounds, matching the old + // DynamicImage::resize() behavior. + let (w, h) = { + let ratio = (w as f64 / img.width() as f64).min(h as f64 / img.height() as f64); + ((img.width() as f64 * ratio).round() as u32, (img.height() as f64 * ratio).round() as u32) + }; + let img = match img.pixel_type() { Some(_) => img, None => {