jay3332 / ril

Rust Imaging Library: A high-level imaging crate for Rust.
https://crates.io/crates/ril
MIT License
81 stars 10 forks source link

Resize keeping aspect ratio? #26

Open ghmendonca opened 11 months ago

ghmendonca commented 11 months ago

Right now the resize function does not preserve the image aspect ratio and there is no way to do that right now. The image crate has methods to achieve this, like resize, resize_to_fill, resize_exact, thumbnail and thumbnail_exact.

This is a big feature missing, and I would love to have methods similar to these listed. I love ril because compared to the image crate, it already includes all the dependencies and the API is amazing, so adding these methods will be a really good addition!

johandalabacka commented 11 months ago

You can resize it while preserving aspect ratio. For example if you want to make it 50% of its original size do something like this:

let (width, height) = image.dimensions();
let new_width = ((width as f32)  * 0.5) as u32;
let new_height = ((height as f32) * 0.5) as u32;
image.resize(new_width, new_height, ResizeAlgorithm::Bicubic);
ghmendonca commented 11 months ago

That works when you want to scale the images, not resize to an exact width or height. I ended up using image-rs code to calculate the new width and height. But it would be cool if this library could add that code internally so people don't have to implement that themselves

johandalabacka commented 11 months ago

Ah, I see

jay3332 commented 11 months ago

This would be a nice addition, I'll consider this for v0.11