This article describes the use of third-party ZKWeb.System.Drawing to implement CAPTCHA functionality under. Net Core.
Tested System: Windows 8.1 64bitUbuntu Server 16.04 LTS 64bitFedora 64bitCentOS 7.2 64bit can achieve the following functions: Open jpg, BMP, ICO, Pngsave JPG, BMP, ICO, pngresize Imagedraw graphics with brush and Penopen font and draw string
The above is the official information.
Introduction of the ZKWeb.System.Drawing project
NuGet introduces the package and will not own Baidu.
No.2 Simple Verification Code generation
int Codew = 80;int Codeh = 30;int fontSize = 16; Random rnd = new Random ();//Color list, for captcha, noise, noise color[] color = {Color.Black, color.red, Color.Blue, Color.green, Color.oran GE, Color.brown, color.brown, color.darkblue};//font list, for captcha string[] Font = {"Times New Roman"};//the character set of the verification code, removing some easily confusing characters/ /write session, Verification code encryption//webhelper.writesession ("Session_verifycode", Md5helper.md5 (Chkcode.tolower (), 16));// Create canvas Bitmap bmp = new Bitmap (Codew, Codeh); Graphics g = graphics.fromimage (BMP); G.clear (color.white);//Draw noise line for (int i = 0; i < 1; i++) {int x1 = rnd. Next (Codew); int y1 = rnd. Next (Codeh); int x2 = rnd. Next (Codew); int y2 = rnd. Next (Codeh); Color clr = color[rnd. Next (color. Length)]; G.drawline (new Pen (CLR), x1, y1, x2, y2);} Draw the CAPTCHA string for (int i = 0; i < chkcode.length; i++) {string fnt = Font[rnd. Next (font. Length)]; Font ft = new Font (FNT, fontSize); Color clr = color[rnd. Next (color. Length)]; g.DrawString (Chkcode[i]. ToString (), FT, new SolidBrush (CLR), (float) i * 18, (float) 0);} Writes the CAPTCHA picture to the memory stream and outputs it in "image/png" format MemoryStream ms = new MemoryStream (); try{bmp. Save (MS, Imageformat.png); Return Ms. ToArray ();} catch (Exception) {return null;} finally{G.dispose (); Bmp. Dispose ();}
No.3 release deployment Run
Straight, no, look at this www.cnblogs.com/niao/p/6057860.html.
Note: Verification code under Windows generates no pressure, I use Ubuntu 14, need to install GDI package, run log will be prompted.
Installation method:
Ubuntu 16.04:
Apt-get Install libgdipluscd/usr/libln-s libgdiplus.so gdiplus.dll
Fedora 23:
DNF Install Libgdipluscd/usr/lib64/ln-s libgdiplus.so.0 Gdiplus.dll
CentOS 7:
Yum Install autoconf automake libtoolyum install freetype-devel fontconfig libxft-develyum install libjpeg-turbo-devel li Bpng-devel giflib-devel libtiff-devel libexif-develyum install glib2-devel cairo-develgit clone https://github.com/ MONO/LIBGDIPLUSCD libgdiplus./autogen.shmakemake installcd/usr/lib64/ln-s/usr/local/lib/libgdiplus.so Gdiplus.dll
"Recommended"
1.. NET core configuration file loading with di injection configuration data
2.. NET Core CLI Tool documentation Dotnet-publish
3. Detailed introduction to ZKEACMS for. Net Core
4. Sharing. NET MVC using forms to validate instance code
5. How do I make HTTP requests under. NET Core?
6. Example tutorials for running zkeacms on CentOS