赞
踩
用来搜索目录中所有的字体信息,并汇总生成fonts.scale文件
yum -y install ttmkfdir
fc-list
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
WORKDIR /app
COPY . .
RUN apt-get update -y && apt-get install -y libgdiplus && apt-get clean && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
EXPOSE 80
ENTRYPOINT ["dotnet", "<你的入口程序集>"]
<!--Nuget依赖-->
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
using SixLabors.ImageSharp; using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Drawing.Processing; using System; using System.Linq; namespace VertifyCode { public class VerifyCodeHelper { private static readonly Color[] Colors = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown,Color.DarkBlue}; private static readonly char[] Chars = { '2','3','4','5','6','8','9', 'A','B','C','D','E','F','G','H','J','K', 'L','M','N','P','R','S','T','W','X','Y' }; //private static readonly int Width = 90; //private static readonly int Height = 35; private static string GenCode(int num) { var code = string.Empty; var r = new Random(); for (int i = 0; i < num; i++) { code += Chars[r.Next(Chars.Length)].ToString(); } return code; } public static (string code, byte[] bytes) CreateValidateGraphic(int CodeLength, int Width = 80, int Height = 40, int FontSize = 14) { var code = GenCode(CodeLength); var r = new Random(); using var image = new Image<Rgba32>(Width, Height); // 字体 var font = SystemFonts.CreateFont(SystemFonts.Families.First().Name, FontSize, FontStyle.Bold); image.Mutate(ctx => { // 白底背景 ctx.Fill(Color.White); // 画验证码 for (int i = 0; i < code.Length; i++) { ctx.DrawText(code[i].ToString() , font , Colors[r.Next(Colors.Length)] , new PointF(20 \* i + 10, r.Next(2, 12))); } // 画干扰线 for (int i = 0; i < 6; i++) { var pen = new Pen(Colors[r.Next(Colors.Length)], 1); var p1 = new PointF(r.Next(Width), r.Next(Height)); var p2 = new PointF(r.Next(Width), r.Next(Height)); ctx.DrawLines(pen, p1, p2); } // 画噪点 for (int i = 0; i < 60; i++) { var pen = new Pen(Colors[r.Next(Colors.Length)], 1); var p1 = new PointF(r.Next(Width), r.Next(Height)); var p2 = new PointF(p1.X + 1f, p1.Y + 1f); ctx.DrawLines(pen, p1, p2); } }); using var ms = new System.IO.MemoryStream(); // 格式 自定义 image.SaveAsPng(ms); return (code, ms.ToArray()); } } }
<!--Nuget依赖-->
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3" />
using SkiaSharp; using System; namespace VertifyCode { public class VerifyCodeImageSharpHelper { private static readonly char[] Chars = { '2','3','4','5','6','8','9', 'A','B','C','D','E','F','G','H','J','K', 'L','M','N','P','R','S','T','W','X','Y' }; private static string GenCode(int num) { var code = string.Empty; var r = new Random(); for (int i = 0; i < num; i++) { code += Chars[r.Next(Chars.Length)].ToString(); } return code; } public static (string code, byte[] bytes) CreateValidateGraphic(int codeLength, int width = 80, int height = 40, int fontSize = 20) { var code = GenCode(codeLength); byte[] imageBytes = null; int image2d_x = 0; int image2d_y = 0; SKRect size; int compensateDeepCharacters = 0; using (SKPaint drawStyle = CreatePaint(fontSize)) { size = MeasureText(code, drawStyle); **网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。** **[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618542503)** **一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。