开源地址:https://github.com/shuaijunlan/nkaptcha
nkaptcha
nkaptcha is a verification code library for Java, it doesn’t rely on any other libraries, is very easy to setup and use, is high availability and high performance . If you would like to change the style of the verification code image, there is several configuration options and the framework is modular so you can write your own morphing code.
If you have a valid issue with the functionality or design of nkaptcha, please click the Issues page and file one.
Features
Installation
- Buid by maven:
<repositories>
<repository>
<id>shuaijunlan-github-maven-repository</id>
<name>shuaijunlan-github-maven-repository</name>
<url>https://raw.githubusercontent.com/shuaijunlan/shuaijunlan.github.io/master</url>
</repository>
</repositories>
<dependencies>
<dependency>
<artifactId>nkaptcha</artifactId>
<groupId>io.github.shuaijunlan</groupId>
<version>1.0.0</version>
</dependency>
</dependencies>
Get Started
You can generate verification code picture like this:
- Output to folder by default properties
VerificationList verificationList = new VerificationList();
BufferedImage bufferedImage = verificationList.pop().getBufferedImage();
String formatName = "jpg";
String pathName = "F:\\test\\" + System.currentTimeMillis() + ".jpg";
ImageIO.write(bufferedImage,
formatName,
new File(pathName));
- In web application by default properties
@GetMapping("nkaptcha")
public void nkaptcha(HttpServletResponse httpServletResponse) throws IOException {
VerificationList verificationList = new VerificationList(properties);
String formatName = "jpg";
ImageIO.write(verificationList.pop().getBufferedImage(),
formatName,
httpServletResponse.getOutputStream());
}
- Also you can change the properties by yourself
Properties properties = new Properties();
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_LINE, "true");
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_POINT, "false");
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_LINE_COUNT, "10");
VerificationList verificationList = new VerificationList(properties);
BufferedImage bufferedImage = verificationList.pop().getBufferedImage();
String formatName = "jpg";
ImageIO.write(verificationList.pop().getBufferedImage(),
formatName,
httpServletResponse.getOutputStream());