Is there a way to control the background color when using rmode=pad #376
-
h=168&w=1100&mode=pad&bgcolor=white Seems to pad with the detected dominate color. I'd like to always pad with transparent or white. I understand there is an api to control bgcolor when doing a pad operation, but I'm unclear on how to hook into this side, I'm only using EnhanceParsedCommand |
Beta Was this translation helpful? Give feedback.
Answered by
JimBobSquarePants
Aug 22, 2024
Replies: 1 comment 3 replies
-
What is EnhanceParsedCommand? You want |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Those images are palette-based PNGs which means they have a fixed color set. I would expect whoever provided these images have been pre-optimized for display on the web assuming any alignment would be done via CSS.
ImageSharp by default will preserve any inbound color palette, in your case you are introducing transparency where there is none previously so the encoder will attempt to find a color in the palette which has the closes Euclidian distance to transparent. For example, blue is closer than white to transparent, so you get blue.
What you need to do in this case is to remove the inbound palette from the image metadata via OnBeforeSaveAsync
Something like the following...
ImageSharpM…