diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor index 1c5ea20e..d5be70fa 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor @@ -210,7 +210,7 @@ private string GetLogo(int fileid) { - var url = ImageUrl(fileid, 100, 100, "", "", "ffffff", 0, false); + var url = ImageUrl(fileid, 100, 100); url = (!string.IsNullOrEmpty(PageState.Alias.Path)) ? url.Substring(PageState.Alias.Path.Length + 1) : url; return Constants.PackageRegistryUrl + url; } diff --git a/Oqtane.Client/Modules/Admin/Themes/Add.razor b/Oqtane.Client/Modules/Admin/Themes/Add.razor index 35178935..df48d6a0 100644 --- a/Oqtane.Client/Modules/Admin/Themes/Add.razor +++ b/Oqtane.Client/Modules/Admin/Themes/Add.razor @@ -212,7 +212,7 @@ private string GetLogo(int fileid) { - var url = ImageUrl(fileid, 100, 100, "", "", "ffffff", 0, false); + var url = ImageUrl(fileid, 100, 100); url = (!string.IsNullOrEmpty(PageState.Alias.Path)) ? url.Substring(PageState.Alias.Path.Length + 1) : url; return Constants.PackageRegistryUrl + url; } diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index a100dd22..636803b1 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -572,7 +572,7 @@ namespace Oqtane.Controllers // validation if (!Enum.TryParse(mode, true, out ResizeMode _)) mode = "crop"; if (!Enum.TryParse(position, true, out AnchorPositionMode _)) position = "center"; - if (!Color.TryParseHex("#" + background, out _)) background = "000000"; + if (!Color.TryParseHex("#" + background, out _)) background = "transparent"; if (!int.TryParse(rotate, out _)) rotate = "0"; rotate = (int.Parse(rotate) < 0 || int.Parse(rotate) > 360) ? "0" : rotate; if (!bool.TryParse(recreate, out _)) recreate = "false"; @@ -644,10 +644,23 @@ namespace Oqtane.Controllers Mode = resizemode, Position = anchorpositionmode, Size = new Size(width, height) - }) - .BackgroundColor(Color.ParseHex("#" + background))); + })); - image.Save(imagepath, new PngEncoder()); + if (background != "transparent") + { + image.Mutate(x => x + .BackgroundColor(Color.ParseHex("#" + background))); + } + + PngEncoder encoder = new PngEncoder + { + ColorType = PngColorType.RgbWithAlpha, + TransparentColorMode = PngTransparentColorMode.Preserve, + BitDepth = PngBitDepth.Bit8, + CompressionLevel = PngCompressionLevel.BestSpeed + }; + + image.Save(imagepath, encoder); } } } diff --git a/Oqtane.Shared/Shared/Utilities.cs b/Oqtane.Shared/Shared/Utilities.cs index cbab8fa3..cdf0e05e 100644 --- a/Oqtane.Shared/Shared/Utilities.cs +++ b/Oqtane.Shared/Shared/Utilities.cs @@ -133,7 +133,7 @@ namespace Oqtane.Shared var url = (alias != null && !string.IsNullOrEmpty(alias.Path)) ? "/" + alias.Path : ""; mode = string.IsNullOrEmpty(mode) ? "crop" : mode; position = string.IsNullOrEmpty(position) ? "center" : position; - background = string.IsNullOrEmpty(background) ? "000000" : background; + background = string.IsNullOrEmpty(background) ? "transparent" : background; return $"{alias?.BaseUrl}{url}{Constants.ImageUrl}{fileId}/{width}/{height}/{mode}/{position}/{background}/{rotate}/{recreate}"; }