Skip to content

Bug with negative background location while drawing an image #2608

Description

@tocsoft

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)

Activity

  1. self-assigned this
    on Dec 8, 2023
  2. tocsoft commented on Dec 10, 2023

    @tocsoft
    MemberAuthor

    fix has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions