轉自:喬達摩
cnblogs.com/xiaxiaolu/p/11280000.html
寫在前面
SixLabors/ImageSharp:https://github.com/SixLabors/ImageSharp
dlemstra/Magick.NET:https://github.com/dlemstra/Magick.NET
mono/SkiaSharp:https://github.com/mono/SkiaSharp
綜合考慮后選擇了:ImageSharp
官方文檔:https://sixlabors.github.io/docs/
成果
Hei.Captcha
一個.NET Core,跨平臺的驗證碼生成工具包,基于ImageSharp。
使用
Install-Package Hei.Captcha
///<summary>
///泡泡中文驗證碼
///</summary>
///<returns></returns>
publicIActionResult BubbleCode()
{
varcode = _securityCode.GetRandomCnText(2);
varimgbyte = _securityCode.GetBubbleCodeByte(code);
returnFile(imgbyte, "image/png");
}
///<summary>
///數字字母組合驗證碼
///</summary>
///<returns></returns>
publicIActionResult HybridCode()
{
varcode = _securityCode.GetRandomEnDigitalText(4);
varimgbyte = _securityCode.GetEnDigitalCodeByte(code);
returnFile(imgbyte, "image/png");
}
高級
參照Demo,通過修改/豐富應用程序運行目錄./fonts目錄下的字體文件,生成更多不同字體組合的驗證碼。
源碼
https://github.com/gebiWangshushu/Hei.Captcha
參考
https://sixlabors.github.io/docs/
責任編輯: