image
image copied to clipboard
add public resize_to_fit and resize_to_fill utility functions
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.
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.
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 Did you find the time for the research :)