Mirror of
0
fork

Configure Feed

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

feat: background patterns (circuitry, concentric, dots, geometry, grid, hexagons, maze, steps, waves)

+44 -27
+2 -2
app/ReleaseImageGenerator.API/Program.cs
··· 20 20 21 21 app.MapGet("/", 22 22 (string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight, 23 - string? primaryColor, SupportedImageFormat? imageFormat) => 23 + string? primaryColor, SupportedImageFormat? imageFormat, SupportedPatternType? backgroundPatternType) => 24 24 { 25 25 var options = new ImageGeneratorOptions(text, width ?? 1920, height ?? 1080, 26 26 fontFamily ?? SupportedFontFamily.readexpro, fontWeight ?? SupportedFontWeight.bold, primaryColor, 27 - imageFormat ?? SupportedImageFormat.png); 27 + imageFormat ?? SupportedImageFormat.png, backgroundPatternType); 28 28 var imageGenerator = new ImageGenerator(options); 29 29 return Results.File(imageGenerator.GenerateImage().ToArray(), imageFormat switch 30 30 {
+3 -1
app/ReleaseImageGenerator.Domain/Implementations/ImageGenerator.cs
··· 13 13 public SupportedFontWeight FontWeight { get; set; } 14 14 public string? PrimaryColor { get; set; } 15 15 public SupportedImageFormat ImageFormat { get; set; } 16 + public SupportedPatternType? PatternType { get; set; } 16 17 17 18 public ImageGenerator(ImageGeneratorOptions options) 18 19 { ··· 23 24 FontWeight = options.fontWeight; 24 25 PrimaryColor = options.primaryColor; 25 26 ImageFormat = options.imageFormat; 27 + PatternType = options.patternType; 26 28 } 27 29 28 30 public MemoryStream GenerateImage() ··· 36 38 : ColorGenerator.GetRandomColor(ColorGenerator.ColorLimitation.NEUTRAL_LIGHTNESS, 37 39 ColorGenerator.ColorLimitation.NEUTRAL_SATURATION); 38 40 BackgroundGenerator.GenerateBackground(canvas, Width, Height, random, primaryColor); 39 - PatternGenerator.GeneratePattern(canvas, Width, Height, random, primaryColor); 41 + PatternGenerator.GeneratePattern(canvas, Width, Height, random, primaryColor, PatternType); 40 42 NoiseGenerator.GenerateNoise(canvas, Width, Height, random); 41 43 if (Text != null) TextGenerator.GenerateText(canvas, Text, Width, Height, FontFamily, FontWeight, primaryColor); 42 44
+22 -1
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, SupportedImageFormat imageFormat); 3 + public record ImageGeneratorOptions( 4 + string? text, 5 + int width, 6 + int height, 7 + SupportedFontFamily fontFamily, 8 + SupportedFontWeight fontWeight, 9 + string? primaryColor, 10 + SupportedImageFormat imageFormat, 11 + SupportedPatternType? patternType); 4 12 5 13 public enum SupportedFontFamily 6 14 { ··· 33 41 png, 34 42 webp 35 43 } 44 + 45 + public enum SupportedPatternType 46 + { 47 + grid, 48 + dots, 49 + waves, 50 + hexagons, 51 + concentric, 52 + circuitry, 53 + maze, 54 + steps, 55 + geometry 56 + }
+17 -23
app/ReleaseImageGenerator.Domain/PatternGenerator.cs
··· 1 - using SkiaSharp; 1 + using ReleaseImageGenerator.Domain.Implementations; 2 + using SkiaSharp; 2 3 using Wacton.Unicolour; 3 4 4 5 namespace ReleaseImageGenerator.Domain; 5 6 6 7 public static class PatternGenerator 7 8 { 8 - public static void GeneratePattern(SKCanvas canvas, int width, int height, Random random, Unicolour primaryColor) 9 + public static void GeneratePattern(SKCanvas canvas, int width, int height, Random random, Unicolour primaryColor, SupportedPatternType? patternType) 9 10 { 10 11 var lightness = primaryColor.Oklch.L; 11 12 12 - // Choose a pattern type randomly 13 - int patternType = random.Next(10); 13 + // Choose a pattern type randomly (except geometry pattern) if not defined by user 14 + var selectedPattern = patternType ?? (SupportedPatternType)random.Next(Enum.GetValues(typeof(SupportedPatternType)).Length - 1); 14 15 15 - switch (patternType) 16 + switch (selectedPattern) 16 17 { 17 - case 0: 18 - // Subtle grid pattern 18 + case SupportedPatternType.grid: 19 19 DrawGridPattern(canvas, width, height, random, lightness); 20 20 break; 21 - case 1: 22 - // Dotted pattern 21 + case SupportedPatternType.dots: 23 22 DrawDottedPattern(canvas, width, height, random, lightness); 24 23 break; 25 - case 2: 26 - // Wavy lines pattern 24 + case SupportedPatternType.waves: 27 25 DrawWavyPattern(canvas, width, height, random, lightness); 28 26 break; 29 - case 3: 30 - // Geometric shapes 27 + case SupportedPatternType.geometry: 31 28 DrawGeometricPattern(canvas, width, height, random, lightness); 32 29 break; 33 - case 4: 34 - // Hexagonal grid 30 + case SupportedPatternType.hexagons: 35 31 DrawHexagonalPattern(canvas, width, height, random, lightness); 36 32 break; 37 - case 5: 38 - // Concentric circles 33 + case SupportedPatternType.concentric: 39 34 DrawConcentricPattern(canvas, width, height, random, lightness); 40 35 break; 41 - case 6: 42 - // Circuit board pattern 36 + case SupportedPatternType.circuitry: 43 37 DrawCircuitPattern(canvas, width, height, random, lightness); 44 38 break; 45 - case 7: 46 - // Maze pattern 39 + case SupportedPatternType.maze: 47 40 DrawMazePattern(canvas, width, height, random, lightness); 48 41 break; 49 - case 8: 50 - // Steps pattern 42 + case SupportedPatternType.steps: 51 43 DrawStepsPattern(canvas, width, height, random, lightness); 52 44 break; 45 + default: 46 + throw new ArgumentOutOfRangeException(); 53 47 } 54 48 } 55 49