diff --git a/README.md b/README.md index c213501..e6ce35e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # EasyCaptcha +![GitHub release](https://img.shields.io/github/release/whvcse/EasyCaptcha.svg?style=flat-square) +![GitHub Release Date](https://img.shields.io/github/release-date/whvcse/EasyCaptcha.svg?style=flat-square) +![JitPack](https://img.shields.io/jitpack/v/whvcse/EasyCaptcha.svg?style=flat-square) +![Hex.pm](https://img.shields.io/hexpm/l/plug.svg?style=flat-square) + + ## 1.简介 -  Java图形验证码,支持gif验证码,可用于Java Web、JavaSE和Android项目。 +  Java图形验证码,支持gif验证码,可用于Java Web、JavaSE项目。 ## 2.效果展示 @@ -146,4 +152,48 @@ public class MainController { ## 4.更多设置 -### +### 4.1.使用Gif验证码 + +```java +public class Test { + + public static void main(String[] args) { + OutputStream outputStream = new FileOutputStream(new File("D:/a/aa.gif")); + + // 三个参数分别为宽、高、位数 + GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5); + + // 设置字体 + gifCaptcha.setFont(new Font("Verdana", Font.PLAIN, 32)); // 有默认字体,可以不用设置 + + // 生成的验证码 + String code = gifCaptcha.text(); + + // 输出图片流 + gifCaptcha.out(outputStream); + } +} +``` + +### 4.2.使用png验证码 + +```java +public class Test { + + public static void main(String[] args) { + OutputStream outputStream = new FileOutputStream(new File("D:/a/aa.gif")); + + // 三个参数分别为宽、高、位数 + SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5); + + // 设置字体 + specCaptcha.setFont(new Font("Verdana", Font.PLAIN, 32)); // 有默认字体,可以不用设置 + + // 生成的验证码 + String code = specCaptcha.text(); + + // 输出图片流 + specCaptcha.out(outputStream); + } +} +``` \ No newline at end of file diff --git a/src/test/java/com/wf/captcha/CaptchaTest.java b/src/test/java/com/wf/captcha/CaptchaTest.java index 641bf70..2385e9d 100644 --- a/src/test/java/com/wf/captcha/CaptchaTest.java +++ b/src/test/java/com/wf/captcha/CaptchaTest.java @@ -2,6 +2,7 @@ package com.wf.captcha; import org.junit.Test; +import java.awt.*; import java.io.File; import java.io.FileOutputStream; @@ -20,8 +21,8 @@ public class CaptchaTest { @Test public void testGIf() throws Exception { - GifCaptcha specCaptcha = new GifCaptcha(130, 48, 5); - System.out.println(specCaptcha.text()); - //specCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif"))); + GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5); + System.out.println(gifCaptcha.text()); + //gifCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif"))); } }