Skip to content

Commit 7736ad3

Browse files
Merge pull request #157 from SixLabors/js/samples
Update samples and add to main solution
2 parents 653cf5f + 7bf8be5 commit 7736ad3

12 files changed

Lines changed: 232 additions & 104 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282

8383
- name: DotNet Build
8484
shell: pwsh
85-
run: ./ci-build.ps1 "${{matrix.options.framework}}"
85+
run: ./ci-build.ps1
8686
env:
8787
SIXLABORS_TESTING: True
8888

ImageSharp.Drawing.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Drawing.Benchmar
324324
EndProject
325325
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedInfrastructure", "shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.shproj", "{68A8CC40-6AED-4E96-B524-31B1158FDEEA}"
326326
EndProject
327+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{528610AC-7C0C-46E8-9A2D-D46FD92FEE29}"
328+
ProjectSection(SolutionItems) = preProject
329+
samples\Directory.Build.props = samples\Directory.Build.props
330+
samples\Directory.Build.targets = samples\Directory.Build.targets
331+
samples\Drawing.Samples.ruleset = samples\Drawing.Samples.ruleset
332+
EndProjectSection
333+
EndProject
334+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawShapesWithImageSharp", "samples\DrawShapesWithImageSharp\DrawShapesWithImageSharp.csproj", "{5493F024-0A3F-420C-AC2D-05B77A36025B}"
335+
EndProject
327336
Global
328337
GlobalSection(SharedMSBuildProjectFiles) = preSolution
329338
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2e33181e-6e28-4662-a801-e2e7dc206029}*SharedItemsImports = 5
@@ -346,6 +355,10 @@ Global
346355
{59804113-1DD4-4F80-8D06-35FF71652508}.Debug|Any CPU.Build.0 = Debug|Any CPU
347356
{59804113-1DD4-4F80-8D06-35FF71652508}.Release|Any CPU.ActiveCfg = Release|Any CPU
348357
{59804113-1DD4-4F80-8D06-35FF71652508}.Release|Any CPU.Build.0 = Release|Any CPU
358+
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
359+
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Debug|Any CPU.Build.0 = Debug|Any CPU
360+
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Release|Any CPU.ActiveCfg = Release|Any CPU
361+
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Release|Any CPU.Build.0 = Release|Any CPU
349362
EndGlobalSection
350363
GlobalSection(SolutionProperties) = preSolution
351364
HideSolutionNode = FALSE
@@ -371,6 +384,7 @@ Global
371384
{EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
372385
{59804113-1DD4-4F80-8D06-35FF71652508} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
373386
{68A8CC40-6AED-4E96-B524-31B1158FDEEA} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
387+
{5493F024-0A3F-420C-AC2D-05B77A36025B} = {528610AC-7C0C-46E8-9A2D-D46FD92FEE29}
374388
EndGlobalSection
375389
GlobalSection(ExtensibilityGlobals) = postSolution
376390
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}

ci-build.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
param(
2-
[Parameter(Mandatory = $true, Position = 0)]
3-
[string]$targetFramework
4-
)
5-
61
dotnet clean -c Release
72

83
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
94

105
# Building for a specific framework.
11-
dotnet build -c Release -f $targetFramework /p:RepositoryUrl=$repositoryUrl
6+
dotnet build -c Release /p:RepositoryUrl=$repositoryUrl

ci-pack.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dotnet clean -c Release
2+
13
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
24

35
# Building for packing and publishing.

samples/Directory.Build.props

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
4+
<!--
5+
Directory.Build.props is automatically picked up and imported by
6+
Microsoft.Common.props. This file needs to exist, even if empty so that
7+
files in the parent directory tree, with the same name, are not imported
8+
instead. They import fairly early and only Sdk.props will have been
9+
imported beforehand. We also don't need to add ourselves to
10+
MSBuildAllProjects, as that is done by the file that imports us.
11+
-->
12+
13+
<!--Set product category-->
14+
<PropertyGroup>
15+
<SixLaborsProjectCategory>samples</SixLaborsProjectCategory>
16+
<IsPackable>false</IsPackable>
17+
</PropertyGroup>
18+
19+
<!-- Import the solution .props file. -->
20+
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.props" />
21+
22+
<PropertyGroup>
23+
<CodeAnalysisRuleSet>..\Drawing.Samples.ruleset</CodeAnalysisRuleSet>
24+
</PropertyGroup>
25+
26+
</Project>

samples/Directory.Build.targets

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
4+
<!--
5+
Directory.Build.targets is automatically picked up and imported by
6+
Microsoft.Common.targets. This file needs to exist, even if empty so that
7+
files in the parent directory tree, with the same name, are not imported
8+
instead. They import fairly late and most other props/targets will have
9+
been imported beforehand. We also don't need to add ourselves to
10+
MSBuildAllProjects, as that is done by the file that imports us.
11+
-->
12+
13+
<!-- Import the solution .targets file. -->
14+
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" />
15+
16+
</Project>
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<DebugType>portable</DebugType>
66
<OutputType>Exe</OutputType>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\..\src\SixLabors.Shapes.Text\SixLabors.Shapes.Text.csproj" />
11-
<ProjectReference Include="..\..\src\SixLabors.Shapes\SixLabors.Shapes.csproj" />
12-
</ItemGroup>
13-
14-
<ItemGroup>
15-
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-dev002919" />
16-
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
17-
<PackageReference Include="System.Runtime.Numerics" Version="4.3.0" />
10+
<ProjectReference Include="..\..\src\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />
1811
</ItemGroup>
1912

2013
</Project>

samples/DrawShapesWithImageSharp/ImageSharpLogo.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
14
using System;
25
using System.Collections.Generic;
36
using System.Numerics;
47
using SixLabors.ImageSharp;
8+
using SixLabors.ImageSharp.Drawing;
9+
using SixLabors.ImageSharp.Drawing.Processing;
510
using SixLabors.ImageSharp.PixelFormats;
611
using SixLabors.ImageSharp.Processing;
712

@@ -16,13 +21,15 @@ public static void SaveLogo(float size, string path)
1621

1722
var center = new Vector2(603);
1823

19-
// segment whose center of rotation should be
24+
// segment whose center of rotation should be
2025
var segmentOffset = new Vector2(301.16968f, 301.16974f);
21-
IPath segment = new Polygon(new LinearLineSegment(new Vector2(230.54f, 361.0261f), new System.Numerics.Vector2(5.8641942f, 361.46031f)),
22-
new CubicBezierLineSegment(new Vector2(5.8641942f, 361.46031f),
23-
new Vector2(-11.715693f, 259.54052f),
24-
new Vector2(24.441609f, 158.17478f),
25-
new Vector2(78.26f, 97.0461f))).Translate(center - segmentOffset);
26+
IPath segment = new Polygon(
27+
new LinearLineSegment(new Vector2(230.54f, 361.0261f), new Vector2(5.8641942f, 361.46031f)),
28+
new CubicBezierLineSegment(
29+
new Vector2(5.8641942f, 361.46031f),
30+
new Vector2(-11.715693f, 259.54052f),
31+
new Vector2(24.441609f, 158.17478f),
32+
new Vector2(78.26f, 97.0461f))).Translate(center - segmentOffset);
2633

2734
// we need to create 6 of theses all rotated about the center point
2835
var segments = new List<IPath>();
@@ -33,23 +40,24 @@ public static void SaveLogo(float size, string path)
3340
segments.Add(s);
3441
}
3542

36-
var colors = new List<Rgba32>() {
37-
Rgba32.FromHex("35a849"),
38-
Rgba32.FromHex("fcee21"),
39-
Rgba32.FromHex("ed7124"),
40-
Rgba32.FromHex("cb202d"),
41-
Rgba32.FromHex("5f2c83"),
42-
Rgba32.FromHex("085ba7"),
43+
var colors = new List<Color>()
44+
{
45+
Color.ParseHex("35a849"),
46+
Color.ParseHex("fcee21"),
47+
Color.ParseHex("ed7124"),
48+
Color.ParseHex("cb202d"),
49+
Color.ParseHex("5f2c83"),
50+
Color.ParseHex("085ba7"),
4351
};
4452

4553
var scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero);
4654

4755
int dimensions = (int)Math.Ceiling(size);
4856
using (var img = new Image<Rgba32>(dimensions, dimensions))
4957
{
50-
img.Mutate(i => i.Fill(Rgba32.Black));
51-
img.Mutate(i => i.Fill(Rgba32.FromHex("e1e1e1ff"), new EllipsePolygon(center, 600f).Transform(scaler)));
52-
img.Mutate(i => i.Fill(Rgba32.White, new EllipsePolygon(center, 600f - 60).Transform(scaler)));
58+
img.Mutate(i => i.Fill(Color.Black));
59+
img.Mutate(i => i.Fill(Color.ParseHex("e1e1e1ff"), new EllipsePolygon(center, 600f).Transform(scaler)));
60+
img.Mutate(i => i.Fill(Color.White, new EllipsePolygon(center, 600f - 60).Transform(scaler)));
5361

5462
for (int s = 0; s < 6; s++)
5563
{

0 commit comments

Comments
 (0)