Skip to content

Commit

Permalink
migrate boom boom
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Dec 11, 2023
1 parent 126d279 commit c806e07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/Edi.Captcha/CaptchaImageGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@ public static CaptchaResult GetImage(int width, int height, string captchaCode,

Font font = SystemFonts.CreateFont(fontName, fontSize, fontStyle);

Random random = new Random();

foreach (char c in captchaCode)
{
var x = rand.Next(5, 10);
var y = rand.Next(6, 13);

var degrees = random.Next(0, 10) * (random.Next(-10, 10) > 0 ? 1 : -1);

var location = new PointF(x + position, y);
imgText.Mutate(ctx => ctx.DrawText(c.ToString(), font, GetRandomDeepColor(), location));
imgText.Mutate(ctx =>
ctx.SetDrawingTransform(Matrix3x2Extensions.CreateRotationDegrees(degrees, new(0, 0)))
.DrawText(c.ToString(), font, GetRandomDeepColor(), location));
position += TextMeasurer.MeasureBounds(c.ToString(), new(font)).Width;
}

Random random = new Random();
var builder = new AffineTransformBuilder();
var rWidth = random.Next(10, width);
var rHeight = random.Next(10, height);
var pointF = new PointF(rWidth, rHeight);
var degrees = random.Next(0, 10) * (random.Next(-10, 10) > 0 ? 1 : -1);
var rotation = builder.PrependRotationDegrees(degrees, pointF);
imgText.Mutate(ctx => ctx.Transform(rotation));

// background layer
int low = 180, high = 255;
var nRend = rand.Next(high) % (high - low) + low;
Expand Down
2 changes: 1 addition & 1 deletion src/Edi.Captcha/Edi.Captcha.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>3.19.2</Version>
<Version>3.20.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>edi.wang</Company>
<Authors>Edi Wang</Authors>
Expand Down

0 comments on commit c806e07

Please sign in to comment.