-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathImageSharpLogo.cs
More file actions
72 lines (59 loc) · 2.67 KB
/
ImageSharpLogo.cs
File metadata and controls
72 lines (59 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.Shapes.DrawShapesWithImageSharp;
public static class ImageSharpLogo
{
public static void SaveLogo(float size, string path)
{
// the point are based on a 1206x1206 shape so size requires scaling from there
float scalingFactor = size / 1206;
Vector2 center = new(603);
// segment whose center of rotation should be
Vector2 segmentOffset = new(301.16968f, 301.16974f);
IPath segment = new Polygon(
new LinearLineSegment(new Vector2(230.54f, 361.0261f), new Vector2(5.8641942f, 361.46031f)),
new CubicBezierLineSegment(
new Vector2(5.8641942f, 361.46031f),
new Vector2(-11.715693f, 259.54052f),
new Vector2(24.441609f, 158.17478f),
new Vector2(78.26f, 97.0461f))).Translate(center - segmentOffset);
// we need to create 6 of theses all rotated about the center point
List<IPath> segments = [];
for (int i = 0; i < 6; i++)
{
float angle = i * ((float)Math.PI / 3);
IPath s = segment.Transform(Matrix3x2.CreateRotation(angle, center));
segments.Add(s);
}
List<Color> colors =
[
Color.ParseHex("35a849"),
Color.ParseHex("fcee21"),
Color.ParseHex("ed7124"),
Color.ParseHex("cb202d"),
Color.ParseHex("5f2c83"),
Color.ParseHex("085ba7")
];
Matrix3x2 scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero);
int dimensions = (int)Math.Ceiling(size);
using (Image<Rgba32> img = new(dimensions, dimensions))
{
img.Mutate(i => i.Fill(Color.Black));
img.Mutate(i => i.Fill(Color.ParseHex("e1e1e1ff"), new EllipsePolygon(center, 600f).Transform(scaler)));
img.Mutate(i => i.Fill(Color.White, new EllipsePolygon(center, 600f - 60).Transform(scaler)));
for (int s = 0; s < 6; s++)
{
img.Mutate(i => i.Fill(colors[s], segments[s].Transform(scaler)));
}
img.Mutate(i => i.Fill(Color.FromPixel(new Rgba32(0, 0, 0, 170)), new ComplexPolygon(new EllipsePolygon(center, 161f), new EllipsePolygon(center, 61f)).Transform(scaler)));
string fullPath = System.IO.Path.GetFullPath(System.IO.Path.Combine("Output", path));
img.Save(fullPath);
}
}
}