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

ExtractArea with x and y = 0 returns the entire image instead of the extracted part #1674

Closed
zenoxs opened this issue Jul 9, 2024 · 5 comments
Milestone

Comments

@zenoxs
Copy link

zenoxs commented Jul 9, 2024

Magick.NET version

13.9.1, Magick.NET-Q8-AnyCPU

Environment (Operating system, version and so on)

WSL Debian

Description

When using the MagickReadSettings with the ExtractArea set to x and y = 0, the created image is the entire image resized by the specified width and height instead of the extracted part. This issue only occurs when x and y are both set to 0. If x is set to 1, the output image is correct.

I also tried with the Magick CLI directly, and everything works as expected.
magick -extract 256x256+0+0 ./demo.png extracted.jpg

Steps to Reproduce

demo.png
demo.png

MagickReadSettings settings = new MagickReadSettings
{
    // ExtractArea = new MagickGeometry("256x256+0+0")
    ExtractArea = new MagickGeometry(
        x: 0,
        y: 0,
        width: 256,
        height: 256
    )
};

using var image = new MagickImage("demo.png", settings);

await image.WriteAsync("extracted.jpg");

Result:
extracted.jpg

Expected:
expected output

@zenoxs zenoxs changed the title ExtractArea with x and y = 0 return the whole image instead of the extract part ExtractArea with x and y = 0 returns the entire image instead of the extracted part Jul 9, 2024
@dlemstra
Copy link
Owner

dlemstra commented Jul 9, 2024

It looks like there is a difference for ImageMagick between 256x256+0+0 and 256x256 for ExtractArea. And when calling ImageMagick the +0+0 is only added when those values are set. I suspect I will need to refactor the MagickGeometry to make this work. And only send the +0+0 when it has been specified otherwise I shouldn't. But this could be a breaking change for someone who has been doing this "by accident". I will need some time to think about this but I think I can only make this change in a major release. Or we need to add a "magic boolean" for this behavior.

@dlemstra
Copy link
Owner

Another option would be to only do this when a constructor overload with both x and y is used. This will probably reduce the impact this change will have on other users.

@zenoxs
Copy link
Author

zenoxs commented Jul 10, 2024

Another option would be to only do this when a constructor overload with both x and y is used. This will probably reduce the impact this change will have on other users.

Thanks for the quick reply!

This solution sounds good to me. For now, I do not have any workaround to deal with this issue other than setting the x value to 1 when it is equal to 0. I understand that this could be a breaking change for some users, but the current behavior is more likely to cause errors.
(In my case I am using the MagickReadSettings to split a very large image into several tiles for tile map layer)

@dlemstra dlemstra added this to the 13.10.0 milestone Jul 12, 2024
@dlemstra
Copy link
Owner

I decided to include x and y when it's zero in toString() when it is specified in one of the constructors. This will become available in the next release.

@zenoxs
Copy link
Author

zenoxs commented Jul 12, 2024

Amazing, thanks for the support 👏

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

No branches or pull requests

2 participants