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

Check dimensions of dynamic image before resizing it #1817

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/dynimage.rs
Expand Up @@ -658,14 +658,22 @@ impl DynamicImage {
}

/// Resize this image using the specified filter algorithm.
/// Returns a new image. The image's aspect ratio is preserved.
/// The image is scaled to the maximum possible size that fits
/// within the bounds specified by `nwidth` and `nheight`.
/// The image's aspect ratio is preserved.
/// Returns a new image if the requested image size is different than the already existing one.
/// Otherwise the function returns a copy of self.
VolkerFelix marked this conversation as resolved.
Show resolved Hide resolved
pub fn resize(&self, nwidth: u32, nheight: u32, filter: imageops::FilterType) -> DynamicImage {
let (width2, height2) =
if (nwidth, nheight) == self.dimensions() {
// Image is already in the desired dimensions --> no need to resize.
VolkerFelix marked this conversation as resolved.
Show resolved Hide resolved
return self.clone();
}
else {
VolkerFelix marked this conversation as resolved.
Show resolved Hide resolved
let (width2, height2) =
resize_dimensions(self.width(), self.height(), nwidth, nheight, false);

self.resize_exact(width2, height2, filter)
return self.resize_exact(width2, height2, filter);
}
}

/// Resize this image using the specified filter algorithm.
Expand Down