Mirror of
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: image formats (png, jpg, webp)

+32 -6
+12 -3
app/ReleaseImageGenerator.API/Program.cs
··· 19 19 app.UseHttpsRedirection(); 20 20 21 21 app.MapGet("/", 22 - (string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight, string? primaryColor) => 22 + (string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight, 23 + string? primaryColor, SupportedImageFormat? imageFormat) => 23 24 { 24 25 var options = new ImageGeneratorOptions(text, width ?? 1920, height ?? 1080, 25 - fontFamily ?? SupportedFontFamily.readexpro, fontWeight ?? SupportedFontWeight.bold, primaryColor); 26 + fontFamily ?? SupportedFontFamily.readexpro, fontWeight ?? SupportedFontWeight.bold, primaryColor, 27 + imageFormat ?? SupportedImageFormat.png); 26 28 var imageGenerator = new ImageGenerator(options); 27 - return Results.File(imageGenerator.GenerateImage().ToArray(), "image/png"); 29 + return Results.File(imageGenerator.GenerateImage().ToArray(), imageFormat switch 30 + { 31 + SupportedImageFormat.jpeg => "image/jpeg", 32 + SupportedImageFormat.jpg => "image/jpeg", 33 + SupportedImageFormat.png => "image/png", 34 + SupportedImageFormat.webp => "image/webp", 35 + _ => "image/png" 36 + }); 28 37 }) 29 38 .WithName("ImageGenerator") 30 39 .WithOpenApi();
+10 -1
app/ReleaseImageGenerator.Domain/Implementations/ImageGenerator.cs
··· 12 12 public SupportedFontFamily FontFamily { get; set; } 13 13 public SupportedFontWeight FontWeight { get; set; } 14 14 public string? PrimaryColor { get; set; } 15 + public SupportedImageFormat ImageFormat { get; set; } 15 16 16 17 public ImageGenerator(ImageGeneratorOptions options) 17 18 { ··· 21 22 FontFamily = options.fontFamily; 22 23 FontWeight = options.fontWeight; 23 24 PrimaryColor = options.primaryColor; 25 + ImageFormat = options.imageFormat; 24 26 } 25 27 26 28 public MemoryStream GenerateImage() ··· 41 43 // Return as PNG 42 44 var stream = new MemoryStream(); 43 45 using var image = surface.Snapshot(); 44 - using var data = image.Encode(SKEncodedImageFormat.Png, 100); 46 + using var data = image.Encode(ImageFormat switch 47 + { 48 + SupportedImageFormat.jpeg => SKEncodedImageFormat.Jpeg, 49 + SupportedImageFormat.jpg => SKEncodedImageFormat.Jpeg, 50 + SupportedImageFormat.png => SKEncodedImageFormat.Png, 51 + SupportedImageFormat.webp => SKEncodedImageFormat.Webp, 52 + _ => SKEncodedImageFormat.Png 53 + }, 100); 45 54 data.SaveTo(stream); 46 55 return stream; 47 56 }
+10 -2
app/ReleaseImageGenerator.Domain/Implementations/ImageGeneratorOptions.cs
··· 1 1 namespace ReleaseImageGenerator.Domain.Implementations; 2 2 3 - public record ImageGeneratorOptions(string? text, int width, int height, SupportedFontFamily fontFamily, SupportedFontWeight fontWeight, string? primaryColor); 3 + public record ImageGeneratorOptions(string? text, int width, int height, SupportedFontFamily fontFamily, SupportedFontWeight fontWeight, string? primaryColor, SupportedImageFormat imageFormat); 4 4 5 5 public enum SupportedFontFamily 6 6 { ··· 24 24 bold, 25 25 medium, 26 26 light 27 - } 27 + } 28 + 29 + public enum SupportedImageFormat 30 + { 31 + jpeg, 32 + jpg, 33 + png, 34 + webp 35 + }