image icon indicating copy to clipboard operation
image copied to clipboard

add public resize_to_fit and resize_to_fill utility functions

Open filnet opened this issue 5 years ago • 3 comments

Proposed API would look like this:

/// Resizes the given size to fit into a new size while preserving the aspect ratio.
/// The returned size can be smaller than the requested size in one or the other dimension.
pub fn resize_to_fit(size: (u32, u32), new_size: (u32, u32)) -> (u32, u32) {
    resize_dimensions(size.0, size.1, new_size.0, new_size.1, false)
}

/// Resizes the given size to fill a new size while preserving the aspect ratio.
/// The returned size can be larger than the requested size in one or the other dimension.
pub fn resize_to_fill(size: (u32, u32), new_size: (u32, u32)) -> (u32, u32) {
    resize_dimensions(size.0, size.1, new_size.0, new_size.1, true)
}

Feel free to comment/suggest alternatives.

If this API is validated, I'll rewrite the functions to get rid of the old resize_dimensions function.

filnet avatar Nov 11 '20 16:11 filnet

Note that DynImage::resize_to_fill() has a slightly different behavior. In addition to resizing it will also crop the image so that it does not exceed the new dimensions.

filnet avatar Nov 11 '20 16:11 filnet

I am sleeping on it for a bit. I don't like to force solutions.

I'll do another round of prior art research and will come back with another proposal.

filnet avatar Nov 18 '20 17:11 filnet

@filnet Did you find the time for the research :)

197g avatar Oct 02 '21 18:10 197g