import com.wf.captcha.*;
import com.wf.captcha.base.Captcha;
import java.io.FileOutputStream;
public class Demo01 {
public static void main(String[] args)throws Exception {
String path = "D:\\Music\\";
SpecCaptcha captcha = new SpecCaptcha(130, 40);
FileOutputStream outputStream = new FileOutputStream(path + "0png类型.png");
System.out.println(captcha.text());
captcha.out(outputStream);
GifCaptcha gifCaptcha = new GifCaptcha(130, 40);
FileOutputStream outputStream1 = new FileOutputStream(path + "1gif类型.gif");
gifCaptcha.setCharType(Captcha.TYPE_ONLY_UPPER);
gifCaptcha.setFont(Captcha.FONT_5);
System.out.println(gifCaptcha.text());
gifCaptcha.out(outputStream1);
ChineseCaptcha chineseCaptcha = new ChineseCaptcha(130, 40);
FileOutputStream outputStream2 = new FileOutputStream(path + "2中文类型.png");
System.out.println(chineseCaptcha.text()); chineseCaptcha.out(outputStream2);
ChineseGifCaptcha chineseGifCaptcha = new ChineseGifCaptcha(130, 40);
FileOutputStream outputStream3 = new FileOutputStream(path + "3中文类型动图.gif");
System.out.println(chineseGifCaptcha.text()); chineseGifCaptcha.out(outputStream3);
ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha(180, 40);
FileOutputStream outputStream4 = new FileOutputStream(path + "4算术类型.png");
arithmeticCaptcha.setLen(3);
System.out.println(arithmeticCaptcha.getArithmeticString());
System.out.println(arithmeticCaptcha.text());
arithmeticCaptcha.out(outputStream4);
}
}
导入以下依赖
<!--图片验证码-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>