private static IImageEncoder GetEncoder(TemplateConfig.Template template, TemplateConfig config) { switch ((template.Format ?? config.TemplateDefaults.Format).ToUpperInvariant()) { case "JPG": case "JPEG": return(new JpegEncoder() { IgnoreMetadata = true, Quality = template.Quality ?? config.TemplateDefaults.Quality ?? 90 }); case "PNG": return(new PngEncoder()); case "BMP": return(new BmpEncoder()); case "GIF": var gifQuantizer = template.GifQuantizer ?? config.TemplateDefaults.GifQuantizer; var paletteSize = template.GifPaletteSize ?? config.TemplateDefaults.GifPaletteSize ?? 0; var quantizer = CreateQuantizerFromString(gifQuantizer, paletteSize); return(new GifEncoder() { IgnoreMetadata = true, Quantizer = quantizer, }); default: throw new ArgumentOutOfRangeException("format"); } }
public string GetImagePath(TemplateConfig.Template template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } return(Path.Combine(_env.ContentRootPath, _options.Value.ImageDirectory, template.File)); }
public string GetFontPath(TemplateConfig.Template template, TemplateConfig config) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } return(Path.Combine(_env.ContentRootPath, _options.Value.FontDirectory, template.Font ?? config.TemplateDefaults.Font)); }
private static string GetMimeType(TemplateConfig.Template template, TemplateConfig config) { switch ((template.Format ?? config.TemplateDefaults.Format).ToUpperInvariant()) { case "JPG": case "JPEG": return("image/jpeg"); case "PNG": return("image/png"); case "BMP": return("image/bmp"); case "GIF": return("image/gif"); default: throw new ArgumentOutOfRangeException("format"); } }
public async Task <string> GetImageUrl(string message, TemplateConfig.Template template) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (template == null) { throw new ArgumentNullException(nameof(template)); } var config = await _configService.GetConfig(); var boxes = template.Boxes ?? config.TemplateDefaults.Boxes; var textLines = _textSplitter.SplitText(message.ToUpper(), boxes.Count); var imageModel = new ImageModel { ImageId = template.Id, Boxes = boxes.SelectWithIndex((box, i) => new TextBox { Text = textLines[i], X = box.X, Y = box.Y, Width = box.Width, Height = box.Height, Vertical = box.Vertical, Horizontal = box.Horizontal, LineColor = box.LineColor, FillColor = box.FillColor, }).ToList() }; var imageRequest = CreateRequest(imageModel); var imageUrl = _urlHelper.AbsoluteAction("Get", "Image", imageRequest); return(imageUrl); }