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.
This commit is contained in:
Kanyin Cai 2026-03-21 13:47:38 +01:00
parent 875d9593b6
commit 3c9e936653

View file

@ -101,6 +101,13 @@ impl Image {
}
fn fir_resize(img: DynamicImage, w: u32, h: u32, alg: ResizeAlg) -> anyhow::Result<DynamicImage> {
// 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 => {