From 60f0fc42802b90c86cb436dd19ee769f21322123 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 30 Oct 2022 15:25:22 +0000 Subject: [PATCH 1/3] Check dimensions of dynamic image before resizing it --- src/dynimage.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dynimage.rs b/src/dynimage.rs index 682e1ebb3b..f096ee6b66 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -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. 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. + return self.clone(); + } + else { + 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. From 46812253f92718d33b6ed810e3d937e6cdb57899 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Oct 2022 15:21:32 +0000 Subject: [PATCH 2/3] Fix review findings --- src/dynimage.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/dynimage.rs b/src/dynimage.rs index f096ee6b66..8444d5d84d 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -658,22 +658,17 @@ 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. pub fn resize(&self, nwidth: u32, nheight: u32, filter: imageops::FilterType) -> DynamicImage { if (nwidth, nheight) == self.dimensions() { - // Image is already in the desired dimensions --> no need to resize. return self.clone(); } - else { - let (width2, height2) = - resize_dimensions(self.width(), self.height(), nwidth, nheight, false); + let (width2, height2) = + resize_dimensions(self.width(), self.height(), nwidth, nheight, false); - return self.resize_exact(width2, height2, filter); - } + self.resize_exact(width2, height2, filter) } /// Resize this image using the specified filter algorithm. From 392798ccefe0e8965bbb37af937f177e9bdae059 Mon Sep 17 00:00:00 2001 From: chillnArmadillo Date: Tue, 1 Nov 2022 12:53:26 +0000 Subject: [PATCH 3/3] Fix white spacing --- src/dynimage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynimage.rs b/src/dynimage.rs index 2813667110..3e0aeec6b9 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -668,7 +668,7 @@ impl DynamicImage { return self.clone(); } let (width2, height2) = - resize_dimensions(self.width(), self.height(), nwidth, nheight, false); + resize_dimensions(self.width(), self.height(), nwidth, nheight, false); self.resize_exact(width2, height2, filter) }