diff --git a/Proxy/HttpProxy.cs b/Proxy/HttpProxy.cs index 5411f36..2f18bd6 100644 --- a/Proxy/HttpProxy.cs +++ b/Proxy/HttpProxy.cs @@ -3367,30 +3367,6 @@ namespace UMC.Proxy } } } - public static bool TryImageConfig(string rook, string confKey, out WebMeta confValue) - { - confValue = null; - if (String.IsNullOrEmpty(confKey) == false) - { - - if (NetClient.TryImageConf(confKey, out confValue)) - { - return true; - } - var mainKey = String.Format("SITE_IMAGE_CONFIG_{0}{1}", rook, MD5(confKey, "")).ToUpper(); - var config = UMC.Data.DataFactory.Instance().Config(mainKey); - if (config != null) - { - confValue = UMC.Data.JSON.Deserialize(config.ConfValue); - if (confValue != null) - { - return true; - } - } - } - return false; - - } public void ProcessRequest() { @@ -4639,5 +4615,128 @@ namespace UMC.Proxy } return false; } + public static bool TryImageConf(string confKey, out WebMeta confValue) + { + confValue = null; + if (String.IsNullOrEmpty(confKey) == false) + { + + var match = System.Text.RegularExpressions.Regex.Match(confKey, "^[h|w|c|t|m|b](\\d+)([-|x]\\d+)?([g|p|j|w|a|o]?)$"); + + if (match.Success) + { + confValue = new WebMeta(); + switch (match.Groups[3].Value) + { + case "g": + confValue.Put("Format", "gif"); + break; + case "j": + confValue.Put("Format", "jpeg"); + break; + case "w": + confValue.Put("Format", "webp"); + break; + case "p": + confValue.Put("Format", "png"); + break; + case "a": + confValue.Put("Format", "avif"); + break; + case "o": + confValue.Put("Format", "Optimal"); + break; + + } + confValue.Put("Width", match.Groups[1].Value); + if (match.Groups[2].Length > 0) + { + switch (match.Groups[0].Value[0]) + { + case '-': + confValue.Put("Width", "-" + match.Groups[1].Value); + confValue.Put("Height", "-" + match.Groups[0].Value); + break; + default: + confValue.Put("Height", match.Groups[2].Value.Substring(1)); + break; + } + } + else + { + + confValue.Put("Height", match.Groups[1].Value); + } + switch (confKey[0]) + { + case 'w': + confValue.Remove("Height"); + break; + case 'h': + confValue.Remove("Width"); + break; + case 'c': + confValue["Model"] = "0"; + break; + case 't': + confValue["Model"] = "1"; + break; + case 'm': + confValue["Model"] = "2"; + break; + case 'b': + confValue["Model"] = "3"; + break; + } + return true; + } + else + { + switch (confKey) + { + case "g": + confValue = new WebMeta().Put("Format", "gif"); + return true; + case "j": + confValue = new WebMeta().Put("Format", "jpeg"); + return true; + case "w": + confValue = new WebMeta().Put("Format", "webp"); + return true; + case "p": + confValue = new WebMeta().Put("Format", "png"); + return true; + + } + } + } + return false; + + } + + public static bool TryImageConfig(string rook, string confKey, out WebMeta confValue) + { + confValue = null; + if (String.IsNullOrEmpty(confKey) == false) + { + + if (TryImageConf(confKey, out confValue)) + { + return true; + } + var mainKey = String.Format("SITE_IMAGE_CONFIG_{0}{1}", rook, MD5(confKey, "")).ToUpper(); + var config = UMC.Data.DataFactory.Instance().Config(mainKey); + if (config != null) + { + confValue = UMC.Data.JSON.Deserialize(config.ConfValue); + if (confValue != null) + { + return true; + } + } + } + return false; + + } } } diff --git a/Proxy/SiteImage.cs b/Proxy/SiteImage.cs index 0f4290b..2f5c12d 100644 --- a/Proxy/SiteImage.cs +++ b/Proxy/SiteImage.cs @@ -6,6 +6,7 @@ using System.IO.MemoryMappedFiles; using System.Linq; using SkiaSharp; using UMC.Data; +using UMC.Web; namespace UMC.Proxy { @@ -271,6 +272,7 @@ namespace UMC.Proxy input.CopyTo(output); } } + static void WateRmark(SKCanvas templateG, int width, int height, SKBitmap watermark, int size, int postion, int padding) { int w = width * size / 100; diff --git a/Proxy/WebServlet.cs b/Proxy/WebServlet.cs index 466ea18..d33a8d1 100644 --- a/Proxy/WebServlet.cs +++ b/Proxy/WebServlet.cs @@ -1554,7 +1554,7 @@ namespace UMC.Proxy context.OutputFinish(); return; } - if (NetClient.TryImageConf(ckey, out ImageConfig)) + if (HttpProxy.TryImageConf(ckey, out ImageConfig)) { var format = ImageConfig["Format"] ?? "Src"; if (String.Equals(format, "Src") == false)