ril icon indicating copy to clipboard operation
ril copied to clipboard

Resize keeping aspect ratio?

Open ghmendonca opened this issue 1 year ago • 4 comments

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!

ghmendonca avatar Dec 07 '23 03:12 ghmendonca

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);

johandalabacka avatar Dec 17 '23 17:12 johandalabacka

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

ghmendonca avatar Dec 17 '23 17:12 ghmendonca

Ah, I see

johandalabacka avatar Dec 17 '23 19:12 johandalabacka

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

jay3332 avatar Dec 20 '23 15:12 jay3332