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

Is it possible to use ResizeMoode = CropScaleMode.Pad and MatteColor = Color.Transparent? #59

Closed
remmus opened this issue Nov 2, 2020 · 5 comments

Comments

@remmus
Copy link

remmus commented Nov 2, 2020

I'm looking to make a number of PNGs the same size, padding the images either horizontally or vertically.

I thought this was working great with the following code

MagicImageProcessor.ProcessImage("C:\\input.png",
     new FileStream("C:\\output.png", FileMode.Create),
     new ProcessImageSettings()
     {
          Width = 3320,
          Height = 1500,
          ResizeMode = CropScaleMode.Pad,
          MatteColor = Color.Transparent,
          SaveFormat = FileFormat.Png
     }
);

The issue I am having is that where it has padded the height or width the background isn't transparent and is actually white. Am I doing something wrong, or does this not work how I expect?

Thanks for any support you can provide

@saucecontrol
Copy link
Owner

That should work. It doesn't look like I have any test cases for Pad with transparent images, though, so I may have something broken. I'll give it a look in a bit.

@saucecontrol
Copy link
Owner

On review, I do actually have test cases for this, and it does work as intended if the source image has transparency. For non-transparent sources, the alpha channel in the MatteColor is ignored to avoid an unnecessary format conversion for the whole image. And since Color.Transparent is actually defined as 0x00FFFFFF, when the alpha channel is ignored, it yields solid white padding.

It seems reasonable to expect that a transparent or semi-transparent matte color should work when padding an image of any format, so I'm going to go ahead and change that behavior.

@remmus
Copy link
Author

remmus commented Nov 3, 2020

Thanks so much for your support on this @saucecontrol really appreciated you looking into this so quickly

@saucecontrol
Copy link
Owner

No problem! Thanks for bringing that to my attention. New release is up with the fix.

@remmus
Copy link
Author

remmus commented Nov 4, 2020

Tested and all works! Thanks again for your time on this. Hugely appreciated

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