The documentation for SixLabors ImageSharp is very limited, and most google searches leads to GitHub, which is not very helpful.
How can I upload a jpg, .Mutate
it with transparent padding and save it as a png with transparency?
This is the code I have so far. If the uploaded image is a png, transparent padding works, but jpgs get black padding:
private static void ResizeAndSavePhoto(Image<Rgba32> img, string path, int squareSize)
{
Configuration.Default.ImageFormatsManager.SetEncoder(PngFormat.Instance, new PngEncoder()
{
ColorType = PngColorType.RgbWithAlpha
});
img.Mutate(x =>
x.Resize(new ResizeOptions
{
Size = new Size(squareSize, squareSize),
Mode = ResizeMode.Pad
}).BackgroundColor(new Rgba32(255, 255, 255, 0))
);
img.Save(path);
return;
}
.SaveAsPng()
takes a filestream, but I have an Image<Rgba32>
and a path...