diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 68147e4f8..84a36886a 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -679,29 +679,43 @@ private string CreateImage(string filepath, int width, int height, string mode, Enum.TryParse(mode, true, out ResizeMode resizemode); Enum.TryParse(position, true, out AnchorPositionMode anchorpositionmode); - image.Mutate(x => x - .AutoOrient() // auto orient the image - .Rotate(angle) - .Resize(new ResizeOptions - { - Mode = resizemode, - Position = anchorpositionmode, - Size = new Size(width, height) - })); + PngEncoder encoder; if (background != "transparent") { image.Mutate(x => x - .BackgroundColor(Color.ParseHex("#" + background))); + .AutoOrient() // auto orient the image + .Rotate(angle) + .Resize(new ResizeOptions + { + Mode = resizemode, + Position = anchorpositionmode, + Size = new Size(width, height), + PadColor = Color.ParseHex("#" + background) + })); + + encoder = new PngEncoder(); } - - PngEncoder encoder = new PngEncoder + else { - ColorType = PngColorType.RgbWithAlpha, - TransparentColorMode = PngTransparentColorMode.Preserve, - BitDepth = PngBitDepth.Bit8, - CompressionLevel = PngCompressionLevel.BestSpeed - }; + image.Mutate(x => x + .AutoOrient() // auto orient the image + .Rotate(angle) + .Resize(new ResizeOptions + { + Mode = resizemode, + Position = anchorpositionmode, + Size = new Size(width, height) + })); + + encoder = new PngEncoder + { + ColorType = PngColorType.RgbWithAlpha, + TransparentColorMode = PngTransparentColorMode.Preserve, + BitDepth = PngBitDepth.Bit8, + CompressionLevel = PngCompressionLevel.BestSpeed + }; + } image.Save(imagepath, encoder); }