mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
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:
parent
875d9593b6
commit
3c9e936653
1 changed files with 7 additions and 0 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue