src/ZKEACMS/Captcha/DefaultImageGenerator.cs
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using System;
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.IO;
using System.Threading.Tasks;
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Jpeg;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
namespace ZKEACMS.Captcha
{
public class DefaultImageGenerator : IImageGenerator
{
public DefaultImageGenerator(IWebHostEnvironment webHostEnvironment)
{
string fontDir = Path.Combine(webHostEnvironment.WebRootPath, "fonts");
var fontCollection = new FontCollection();
foreach (var item in Directory.GetFiles(fontDir, "*.ttf"))
{
fontCollection.Add(item);
}
FontFamilies = fontCollection.Families.ToArray();
}
public FontFamily[] FontFamilies { get; set; }
public Color[] TextColor { get; set; } = new Color[] { Color.Blue, Color.Black, Color.Red, Color.Brown, Color.Green };
public Color[] DrawLinesColor { get; set; } = new Color[] { Color.LightBlue, Color.LightCoral, Color.LightCyan, Color.LightGray, Color.LightPink, Color.LightSalmon, Color.LightSeaGreen, Color.LightSkyBlue, Color.LightSlateGray, Color.LightSteelBlue };
public float MinLineThickness { get; set; } = 0.7f;
public float MaxLineThickness { get; set; } = 2.0f;
public ushort Width { get; set; } = 200;
public ushort Height { get; set; } = 70;
public ushort NoiseRate { get; set; } = 300;
public Color[] NoiseRateColor { get; set; } = new Color[] { Color.LightBlue, Color.LightCoral, Color.LightCyan, Color.LightGray, Color.LightPink, Color.LightSalmon, Color.LightSeaGreen, Color.LightSkyBlue, Color.LightSlateGray, Color.LightSteelBlue };
public byte FontSize { get; set; } = 45;
public FontStyle FontStyle { get; set; } = FontStyle.Regular;
public EncoderTypes EncoderType { get; set; } = EncoderTypes.Jpeg;
public IImageEncoder Encoder { get { return GetEncoder(EncoderType); } }
public byte DrawLines { get; set; } = 5;
public byte MaxRotationDegrees { get; set; } = 5;
public byte[] Generate(string text)
{
byte[] result;
using (var imgText = new Image<Rgba32>(Width, Height))
{
float position = 0;
Random random = new Random();
byte startWith = (byte)random.Next(5, 10);
imgText.Mutate(ctx => ctx.BackgroundColor(Color.Transparent));
后面还有 97 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。