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

Bug with negative background location while drawing an image #2608

Closed
tocsoft opened this issue Dec 8, 2023 · 1 comment · Fixed by #2609
Closed

Bug with negative background location while drawing an image #2608

tocsoft opened this issue Dec 8, 2023 · 1 comment · Fixed by #2609
Assignees

Comments

@tocsoft
Copy link
Member

tocsoft commented Dec 8, 2023

We incorrectly calculate the updated area of interest of the foreground image when applying a negative offset to the background drawing location.

I checked the source code and I think I see the issue around these lines:

foregroundRectangle.Width += this.BackgroundLocation.X;

The foregroundRectangle.Width is adjusted by the background location X value if it was negative. This is resulting in cropping off the right side of the top image, not the left. Same for the Y direction just below that.

I created a test project to demonstrate the difference to make sure I wasn't going crazy, but here is an illustration:

imagesharp-3 0 2 Above: 3.0.2 behavior. The top/left of the top image is lost (expected due to negative coordinates).

imagesharp-3 1-intended
Above: what I believe the code in 3.1 is intended to do. The output would remain the same. I believe adjusting the rectangle's X an Y (in addition to removing it from the Width and Height) could have this effect. I am not an expert at what's happening below there, though, so I could be wrong.

imagesharp-3 1-actual
Above: what is actually happening. The top image is indeed painted in the same box, but it originates from the top left corner and cuts off the bottom/right of the image instead of the top/left.

Thanks again for your time!

Originally posted by @aceoft in #2603 (comment)

@tocsoft
Copy link
Member Author

tocsoft commented Dec 10, 2023

fix has been merged

@tocsoft tocsoft closed this as completed Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant