find-closest-fix
All checks were successful
deploy / deploy (push) Successful in 1m1s

This commit is contained in:
Untone 2024-10-23 17:13:45 +03:00
parent 2aca57c86a
commit 7fc29f6b7e

View File

@ -85,4 +85,12 @@ pub async fn generate_thumbnails(image: &DynamicImage) -> Result<HashMap<u32, Ve
}
Ok(thumbnails)
}
}
/// Выбирает ближайший подходящий размер из предопределённых.
pub fn find_closest_width(requested_width: u32) -> u32 {
*THUMB_WIDTHS
.iter()
.min_by_key(|&&width| (width as i32 - requested_width as i32).abs())
.unwrap_or(&THUMB_WIDTHS[0]) // Возвращаем самый маленький размер, если ничего не подошло
}