Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize keeping aspect ratio? #26

Open
ghmendonca opened this issue Dec 7, 2023 · 4 comments
Open

Resize keeping aspect ratio? #26

ghmendonca opened this issue Dec 7, 2023 · 4 comments

Comments

@ghmendonca
Copy link

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
Copy link

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
Copy link
Author

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
Copy link

Ah, I see

@jay3332
Copy link
Owner

jay3332 commented Dec 20, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants