Image crate - resize

The resize function in the image crate seems to preserve aspect ratio - that's not what I expected - isn't it supposed to change it depending on supplied new width/height?

let mut img = image::open("image.png").unwrap();
println!("dim: {:?}", img.dimensions());
img = image::DynamicImage::resize(&img, 50, 25, image::imageops::FilterType::Lanczos3);
println!("dim: {:?}", img.dimensions());

dim: (102, 100)

dim: (26, 25)


You are calling DynamicImage::resize, but you linked the documentation for imageops::resize. They are not the same function, and don't have the same behaviour.

I found this out by searching the image issue tracker for "resize aspect", and found someone who made the exact same mistake you have. You want to either use the function you linked, or DyanmicImage::resize_exact.

Moral of the story: make sure the documentation you're looking at is actually for the thing you're using. :slight_smile:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.