fix(02-01): add max(1.0) safety clamp to aspect ratio calculation

This commit is contained in:
Kanyin Cai 2026-03-21 14:28:23 +01:00
parent 3c9e936653
commit fc71331305

View file

@ -105,7 +105,10 @@ impl Image {
// 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)
(
(img.width() as f64 * ratio).round().max(1.0) as u32,
(img.height() as f64 * ratio).round().max(1.0) as u32,
)
};
let img = match img.pixel_type() {