banner
NEWS LETTER

Captcha生成验证码

Scroll down

captcha

easy-captcha是生成图形验证码的Java类库,支持gif、中文、算术等类型,可用于Java Web、JavaSE等项目。参考地址:https://gitee.com/whvse/EasyCaptcha

maven坐标:

1
2
3
4
5
6
7
8
9
10
11

<dependency>

<groupId>com.github.whvcse</groupId>

<artifactId>easy-captcha</artifactId>

<version>1.6.2</version>

</dependency>

效果展示:

20231010104543

使用方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

package com.itheima.pinda;


import com.wf.captcha.ArithmeticCaptcha;

import com.wf.captcha.base.Captcha;

import java.io.File;

import java.io.FileOutputStream;


publicclassEasyCaptchaTest {

publicstaticvoidmain(String[] args) throwsException{

//算术类型图片验证码

Captchacaptcha = newArithmeticCaptcha(115, 42);//指定图片的宽度和高度

captcha.setCharType(2);

captcha.out(newFileOutputStream(newFile("d:\\hello.png")));

Stringtext = captcha.text();

System.out.println(text);

}

}

Other Articles