Mirror of
0
fork

Configure Feed

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

support 13 fonts, close #7

+66 -41
+26 -3
README.md
··· 2 2 3 3 Get your release image from [https://release-image-generator.trueberryless.org/](https://release-image-generator.trueberryless.org/) and adjust some parameters in the URL: 4 4 5 - - text: Configure the text display in the middle of the image: [https://release-image-generator.trueberryless.org?text=2.0](https://release-image-generator.trueberryless.org?text=2.0) 5 + - text: Configure the text display in the middle of the image: [https://release-image-generator.trueberryless.org?text=2.0](https://release-image-generator.trueberryless.org?text=2.0), by default there is no text 6 6 - width & height: Configure the width and height of the image: [https://release-image-generator.trueberryless.org?width=1560&height=640](https://release-image-generator.trueberryless.org?width=1560&height=640) 7 - - font: Configure the font family used: [https://release-image-generator.trueberryless.org?font=JETBRAINS_BOLD](https://release-image-generator.trueberryless.org?font=JETBRAINS_BOLD) 8 - You can choose between three fonts, each with three boldness levels: `JETBRAINS`, `READEX` and `SOURCE_CODE` (families) with `BOLD`, `MEDIUM` and `LIGHT` (boldness), separated by `_` (underscore) makes 9 possibilities. 7 + - fontFamily & fontWeight: Configure the font family and weight used: [https://release-image-generator.trueberryless.org?fontFamily=jetbrains&fontWeight=bold](https://release-image-generator.trueberryless.org?fontFamily=jetbrains&fontWeight=bold) 8 + 9 + Family Options: 10 + 11 + - `bigshoulders` 12 + - `inter` 13 + - `jetbrainsmono` 14 + - `lato` 15 + - `opensans` 16 + - `poppins` 17 + - `quicksand` 18 + - `raleway` 19 + - `readexpro` 20 + - `roboto` 21 + - `robotomono` 22 + - `rubik` 23 + - `sourcecodepro` 24 + 25 + Weight Options: 26 + 27 + - `bold` 28 + - `medium` 29 + - `light` 30 + 31 + Every family works with every weight. 9 32 10 33 ## License 11 34
+11 -9
app/ReleaseImageGenerator.API/Program.cs
··· 20 20 21 21 app.UseHttpsRedirection(); 22 22 23 - app.MapGet("/", (string? text, int? width, int? height, SupportedFonts? font) => 24 - { 25 - var options = new ImageGeneratorOptions(text, width ?? 1920, height ?? 1080, font ?? SupportedFonts.READEX_BOLD); 26 - var imageGenerator = new ImageGenerator(options); 27 - return Results.File(imageGenerator.GenerateImage().ToArray(), "image/png"); 28 - }) 29 - .WithName("ImageGenerator") 30 - .WithOpenApi(); 23 + app.MapGet("/", 24 + (string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight) => 25 + { 26 + var options = new ImageGeneratorOptions(text, width ?? 1920, height ?? 1080, 27 + fontFamily ?? SupportedFontFamily.readexpro, fontWeight ?? SupportedFontWeight.bold); 28 + var imageGenerator = new ImageGenerator(options); 29 + return Results.File(imageGenerator.GenerateImage().ToArray(), "image/png"); 30 + }) 31 + .WithName("ImageGenerator") 32 + .WithOpenApi(); 31 33 32 - app.Run(); 34 + app.Run();
app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-BoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-ExtraBold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-ExtraBoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-ExtraLight.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-ExtraLightItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Italic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-LightItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-MediumItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Regular.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-SemiBold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-SemiBoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-Thin.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/JetBrainsMono-ThinItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/ReadexPro-ExtraLight.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/ReadexPro-Regular.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/ReadexPro-SemiBold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-Black.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-BlackItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-BoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-ExtraBold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-ExtraBoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-ExtraLight.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-ExtraLightItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-Italic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-LightItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-MediumItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-Regular.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-SemiBold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/SourceCodePro-SemiBoldItalic.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/bigshoulders-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/bigshoulders-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/bigshoulders-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/inter-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/inter-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/inter-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/lato-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/lato-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/lato-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/opensans-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/opensans-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/opensans-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/poppins-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/poppins-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/poppins-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/quicksand-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/quicksand-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/quicksand-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/raleway-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/raleway-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/raleway-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/roboto-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/roboto-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/roboto-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/robotomono-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/robotomono-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/robotomono-medium.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/rubik-bold.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/rubik-light.ttf

This is a binary file and will not be displayed.

app/ReleaseImageGenerator.API/fonts/rubik-medium.ttf

This is a binary file and will not be displayed.

+5 -3
app/ReleaseImageGenerator.Domain/Implementations/ImageGenerator.cs
··· 9 9 public string? Text { get; set; } 10 10 public int Width { get; set; } 11 11 public int Height { get; set; } 12 - public SupportedFonts Font { get; set; } 12 + public SupportedFontFamily FontFamily { get; set; } 13 + public SupportedFontWeight FontWeight { get; set; } 13 14 14 15 public ImageGenerator(ImageGeneratorOptions options) 15 16 { 16 17 Text = options.text; 17 18 Width = options.width; 18 19 Height = options.height; 19 - Font = options.font; 20 + FontFamily = options.fontFamily; 21 + FontWeight = options.fontWeight; 20 22 } 21 23 22 24 public MemoryStream GenerateImage() ··· 28 30 var primaryColor = BackgroundGenerator.GenerateBackground(canvas, Width, Height, random); 29 31 PatternGenerator.GeneratePattern(canvas, Width, Height, random, primaryColor); 30 32 NoiseGenerator.GenerateNoise(canvas, Width, Height, random); 31 - if (Text != null) TextGenerator.GenerateText(canvas, Text, Width, Height, Font, primaryColor); 33 + if (Text != null) TextGenerator.GenerateText(canvas, Text, Width, Height, FontFamily, FontWeight, primaryColor); 32 34 33 35 // Return as JPEG 34 36 var stream = new MemoryStream();
+22 -11
app/ReleaseImageGenerator.Domain/Implementations/ImageGeneratorOptions.cs
··· 1 1 namespace ReleaseImageGenerator.Domain.Implementations; 2 2 3 - public record ImageGeneratorOptions(string? text, int width, int height, SupportedFonts font); 3 + public record ImageGeneratorOptions(string? text, int width, int height, SupportedFontFamily fontFamily, SupportedFontWeight fontWeight); 4 + 5 + public enum SupportedFontFamily 6 + { 7 + bigshoulders, 8 + inter, 9 + jetbrainsmono, 10 + lato, 11 + opensans, 12 + poppins, 13 + quicksand, 14 + raleway, 15 + readexpro, 16 + roboto, 17 + robotomono, 18 + rubik, 19 + sourcecodepro 20 + } 4 21 5 - public enum SupportedFonts 22 + public enum SupportedFontWeight 6 23 { 7 - JETBRAINS_LIGHT, 8 - JETBRAINS_MEDIUM, 9 - JETBRAINS_BOLD, 10 - READEX_LIGHT, 11 - READEX_MEDIUM, 12 - READEX_BOLD, 13 - SOURCE_CODE_LIGHT, 14 - SOURCE_CODE_MEDIUM, 15 - SOURCE_CODE_BOLD, 24 + bold, 25 + medium, 26 + light 16 27 }
+2 -15
app/ReleaseImageGenerator.Domain/TextGenerator.cs
··· 7 7 8 8 public static class TextGenerator 9 9 { 10 - public static void GenerateText(SKCanvas canvas, string text, int width, int height, SupportedFonts font, Unicolour primaryColor) 10 + public static void GenerateText(SKCanvas canvas, string text, int width, int height, SupportedFontFamily fontFamily, SupportedFontWeight fontWeight, Unicolour primaryColor) 11 11 { 12 - // Load JetBrains Mono font 13 - var typeface = font switch 14 - { 15 - SupportedFonts.READEX_BOLD => SKTypeface.FromFile("./fonts/ReadexPro-Bold.ttf"), 16 - SupportedFonts.READEX_MEDIUM => SKTypeface.FromFile("./fonts/ReadexPro-Medium.ttf"), 17 - SupportedFonts.READEX_LIGHT => SKTypeface.FromFile("./fonts/ReadexPro-Light.ttf"), 18 - SupportedFonts.JETBRAINS_BOLD => SKTypeface.FromFile("./fonts/JetbrainsMono-Bold.ttf"), 19 - SupportedFonts.JETBRAINS_MEDIUM => SKTypeface.FromFile("./fonts/JetbrainsMono-Medium.ttf"), 20 - SupportedFonts.JETBRAINS_LIGHT => SKTypeface.FromFile("./fonts/JetbrainsMono-Light.ttf"), 21 - SupportedFonts.SOURCE_CODE_BOLD => SKTypeface.FromFile("./fonts/SourceCodePro-Bold.ttf"), 22 - SupportedFonts.SOURCE_CODE_MEDIUM => SKTypeface.FromFile("./fonts/SourceCodePro-Medium.ttf"), 23 - SupportedFonts.SOURCE_CODE_LIGHT => SKTypeface.FromFile("./fonts/SourceCodePro-Light.ttf"), 24 - _ => SKTypeface.Default 25 - }; 12 + var typeface = SKTypeface.FromFile($"./fonts/{fontFamily.ToString()}-{fontWeight.ToString()}.ttf") ?? SKTypeface.FromFile($"./fonts/readexpro-bold.ttf") ?? SKTypeface.Default; 26 13 var fontsize = GetMaxFontSize(width - width / 3, typeface, text, 1f, width > height ? height / 3 : width / 3); 27 14 28 15 // Calculate text size and position