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

Conversation

VolkerFelix
Copy link
Contributor

Should fix the issue: #1738

Not super happy with it since I'm cloning self but I didn't want to change the return type to &DynamicImage e.g.
Let me know if you have a better idea on how to make this more efficient :)

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple stylistic suggestions, but the code itself looks good

src/dynimage.rs Outdated Show resolved Hide resolved
src/dynimage.rs Outdated Show resolved Hide resolved
src/dynimage.rs Outdated Show resolved Hide resolved
@fintelia
Copy link
Contributor

As a side note, trying to change the return type to &DynamicImage would cause borrow checker errors in the more common case where the dimensions do not match. There's even fancier ways to work around that, but they would make things harder for end users. Ultimately, I think keeping the types as they are is the right decision.

@VolkerFelix
Copy link
Contributor Author

As a side note, trying to change the return type to &DynamicImage would cause borrow checker errors in the more common case where the dimensions do not match. There's even fancier ways to work around that, but they would make things harder for end users. Ultimately, I think keeping the types as they are is the right decision.

Yeah, for the return by reference to work, I would have needed to change the common case when the dimensions do not match. I didn't want to go down that way.
Thanks for your explanations :)

@fintelia
Copy link
Contributor

There's now just a small rustfmt issue to resolve:

/home/runner/.cargo/bin/cargo fmt -- --check
Diff in /home/runner/work/image/image/src/dynimage.rs at line 668:
             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)
     }

@VolkerFelix
Copy link
Contributor Author

There's now just a small rustfmt issue to resolve:

/home/runner/.cargo/bin/cargo fmt -- --check
Diff in /home/runner/work/image/image/src/dynimage.rs at line 668:
             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)
     }

Should be fixed now

@fintelia fintelia merged commit a7026e9 into image-rs:master Nov 1, 2022
@fintelia
Copy link
Contributor

fintelia commented Nov 1, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants