It's possible to change the background color when resizing image with mode Pad. Now is always black, but I would like to change it to other colors.
newImage.Mutate(x => x
.Resize(new SixLabors.ImageSharp.Processing.ResizeOptions
{
Size = new SixLabors.Primitives.Size(newWidth, newHieght),
Mode = SixLabors.ImageSharp.Processing.ResizeMode.Pad
})
);
Searching inside the package I found the following extension "BackgroundColor" that meet my needs.
newImage.Mutate(x => x
.Resize(new SixLabors.ImageSharp.Processing.ResizeOptions
{
Size = new SixLabors.Primitives.Size(newWidth, newHieght),
Mode = SixLabors.ImageSharp.Processing.ResizeMode.Pad
})
.BackgroundColor(new Rgba32(12, 12, 221))
);
Reopening as the solution can be improved upon.
We should add a parameter to the explicit Pad method to allow a shortcut to setting the color.
.Mutate(x => x.Pad(int width, int height, TPixel color))
.Mutate(x => x.Pad(GraphicsOptions options, int width, int height, TPixel color))
Resize itself will probably stay the same as we don't want to make ResizeOptions a generic type.
1 year later and I've decided against merging the two methods as it adds internal complexity that I don't think is worth it when you can simply chain commands like above.
Actually. I'm being an idiot. Gimme 5 minutes.
Most helpful comment
Solution
Searching inside the package I found the following extension "BackgroundColor" that meet my needs.
Example