Generate header using ImageSharp
|
@ -0,0 +1,19 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Backgrounds\" />
|
||||||
|
<Folder Include="Avatars\" />
|
||||||
|
<Folder Include="fonts\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ImageSharp" Version="1.0.0-alpha9-00139" />
|
||||||
|
<PackageReference Include="ImageSharp.Drawing" Version="1.0.0-alpha9-00134" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
После Ширина: | Высота: | Размер: 21 KiB |
После Ширина: | Высота: | Размер: 15 KiB |
После Ширина: | Высота: | Размер: 16 KiB |
После Ширина: | Высота: | Размер: 1.1 MiB |
После Ширина: | Высота: | Размер: 48 KiB |
|
@ -0,0 +1,132 @@
|
||||||
|
using ImageSharp;
|
||||||
|
using ImageSharp.Drawing.Brushes;
|
||||||
|
using SixLabors.Fonts;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace AvatarOnBack
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
private static FontCollection fontCollection;
|
||||||
|
private static Font iconFont;
|
||||||
|
private static Font textFont;
|
||||||
|
private static Font titleFont;
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
fontCollection = new FontCollection();
|
||||||
|
iconFont = fontCollection.Install("fonts/fontawesome-webfont.ttf");
|
||||||
|
titleFont = fontCollection.Install("fonts/Lato-Bold.ttf");
|
||||||
|
textFont = fontCollection.Install("fonts/Lato-Regular.ttf");
|
||||||
|
|
||||||
|
var avatars = Directory.EnumerateFiles("Avatars");
|
||||||
|
var backgrounds = Directory.EnumerateFiles("Backgrounds");
|
||||||
|
Directory.CreateDirectory("output");
|
||||||
|
|
||||||
|
foreach (var format in new[] { "png", "jpg" })
|
||||||
|
{
|
||||||
|
int counter = 0;
|
||||||
|
foreach (var a in avatars)
|
||||||
|
{
|
||||||
|
foreach (var b in backgrounds)
|
||||||
|
{
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
GenerateImage(a, b, "\uf006", "Serenity", 2, 142, 900004, $"output/result-{counter}.{format}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void GenerateImage(string avatarUrl, string backgroundUrl, string icon, string name, int rank, int level, int ep, string outputPath)
|
||||||
|
{
|
||||||
|
using (var output = new Image<Rgba32>(400, 222))
|
||||||
|
{
|
||||||
|
DrawBackground(backgroundUrl, output);
|
||||||
|
|
||||||
|
DrawStats(rank, level, ep, output);
|
||||||
|
|
||||||
|
DrawTitle(icon, name, output);
|
||||||
|
|
||||||
|
DrawAvatar(avatarUrl, output);
|
||||||
|
|
||||||
|
output.Save(outputPath);
|
||||||
|
} // dispose of output to help save memory
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawBackground(string backgroundUrl, Image<Rgba32> output)
|
||||||
|
{
|
||||||
|
using (Image<Rgba32> background = Image.Load(backgroundUrl)) // 400x222
|
||||||
|
{
|
||||||
|
background.Resize(new ImageSharp.Processing.ResizeOptions
|
||||||
|
{
|
||||||
|
Mode = ImageSharp.Processing.ResizeMode.Crop,
|
||||||
|
Size = new ImageSharp.Size(output.Width, output.Height)
|
||||||
|
});
|
||||||
|
|
||||||
|
//draw on the background
|
||||||
|
output.DrawImage(background, 1, new ImageSharp.Size(400, 222), new Point(0, 0));
|
||||||
|
} // once draw it can be disposed as its no longer needed in memory
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawAvatar(string avatarUrl, Image<Rgba32> output)
|
||||||
|
{
|
||||||
|
var avatarPosition = new Rectangle(42, 125, 57, 57);
|
||||||
|
var avatarPadding = 1;
|
||||||
|
// avatar background
|
||||||
|
output.Fill(Rgba32.Gainsboro, new Rectangle(avatarPosition.X - avatarPadding, avatarPosition.Y - avatarPadding, avatarPosition.Width + (avatarPadding * 2), avatarPosition.Height + (avatarPadding * 2)));
|
||||||
|
|
||||||
|
using (var avatar = Image.Load(avatarUrl)) // 57x57
|
||||||
|
{
|
||||||
|
avatar.Resize(new ImageSharp.Processing.ResizeOptions
|
||||||
|
{
|
||||||
|
Mode = ImageSharp.Processing.ResizeMode.Crop,
|
||||||
|
Size = avatarPosition.Size
|
||||||
|
});
|
||||||
|
|
||||||
|
output.DrawImage(avatar, 1, avatarPosition.Size, avatarPosition.Location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawStats(int rank, int level, int ep, Image<Rgba32> output)
|
||||||
|
{
|
||||||
|
Rgba32 statsColor = Rgba32.Gainsboro;
|
||||||
|
statsColor.A = 210;
|
||||||
|
// stats background
|
||||||
|
output.Fill(statsColor, new Rectangle(56, 174, 345, 48));
|
||||||
|
|
||||||
|
// measure each string and split the margin between them??
|
||||||
|
var font = new Font(textFont, 20, FontStyle.Regular);
|
||||||
|
|
||||||
|
// rank
|
||||||
|
output.DrawText($"Rank: {rank}", font, Rgba32.Gray, new System.Numerics.Vector2(108, 191), new ImageSharp.Drawing.TextGraphicsOptions
|
||||||
|
{
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left
|
||||||
|
});
|
||||||
|
output.DrawText($"Level: {level}", font, Rgba32.Gray, new System.Numerics.Vector2(235, 191), new ImageSharp.Drawing.TextGraphicsOptions
|
||||||
|
{
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center
|
||||||
|
});
|
||||||
|
output.DrawText($"EP: {ep}", font, Rgba32.Gray, new System.Numerics.Vector2(394, 191), new ImageSharp.Drawing.TextGraphicsOptions
|
||||||
|
{
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Right
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawTitle(string icon, string name, Image<Rgba32> output)
|
||||||
|
{
|
||||||
|
var titleColor = Rgba32.DimGray;
|
||||||
|
titleColor.A = 220;
|
||||||
|
// title background
|
||||||
|
output.Fill(Rgba32.DimGray, new Rectangle(100, 134, 300, 40));
|
||||||
|
output.DrawText(icon, new Font(iconFont, 22), Rgba32.White, new System.Numerics.Vector2(114, 142));
|
||||||
|
output.DrawText(name, new Font(titleFont, 32, FontStyle.Bold), Rgba32.White, new System.Numerics.Vector2(140, 128));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
После Ширина: | Высота: | Размер: 23 KiB |
После Ширина: | Высота: | Размер: 179 KiB |
После Ширина: | Высота: | Размер: 11 KiB |
После Ширина: | Высота: | Размер: 97 KiB |
После Ширина: | Высота: | Размер: 22 KiB |
После Ширина: | Высота: | Размер: 177 KiB |
После Ширина: | Высота: | Размер: 11 KiB |
После Ширина: | Высота: | Размер: 95 KiB |
После Ширина: | Высота: | Размер: 22 KiB |
После Ширина: | Высота: | Размер: 178 KiB |
После Ширина: | Высота: | Размер: 11 KiB |
После Ширина: | Высота: | Размер: 96 KiB |
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26403.7
|
VisualStudioVersion = 15.0.26430.6
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WaterMarkSample", "WaterMarkSample\WaterMarkSample.csproj", "{06858879-8323-4F32-8260-EFA17EC1DD4F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WaterMarkSample", "WaterMarkSample\WaterMarkSample.csproj", "{06858879-8323-4F32-8260-EFA17EC1DD4F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordArt", "WordArt\WordArt.csproj", "{A5E91B24-8395-4482-A1A9-087AC9EF5492}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordArt", "WordArt\WordArt.csproj", "{A5E91B24-8395-4482-A1A9-087AC9EF5492}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvatarOnBack", "AvatarOnBack\AvatarOnBack.csproj", "{3475CDE1-D623-4563-A592-F9A0A61FE28F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -21,6 +23,10 @@ Global
|
||||||
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A5E91B24-8395-4482-A1A9-087AC9EF5492}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3475CDE1-D623-4563-A592-F9A0A61FE28F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3475CDE1-D623-4563-A592-F9A0A61FE28F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3475CDE1-D623-4563-A592-F9A0A61FE28F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3475CDE1-D623-4563-A592-F9A0A61FE28F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|