Java类
目前只支持在windows上运行,因为linux上没有对应的字体,
使用默认字体,可以迁移到任意服务器。
class="java" name="code">
package com.xxx.catcha;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import javax.imageio.ImageIO;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.util.Config;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws IOException
{
Properties props = new Properties();
//可选字符
props.put("kaptcha.textproducer.char.string", "0123456789一二三四五六七八九");
//验证码字体
props.put("kaptcha.textproducer.font.names", "华文彩云");
//验证码字数
props.put("kaptcha.textproducer.char.length", "4");
Config config = new Config(props);
Producer producer = (Producer)config.getProducerImpl();
String capText = producer.createText();
BufferedImage bi = producer.createImage(capText);
FileOutputStream out = new FileOutputStream("kaptcha.jpg");
ImageIO.write(bi, "jpg", out);
}
}
pom.xml文件
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.xxx
catcha
0.0.1-SNAPSHOT
jar
catcha
http://maven.apache.org
UTF-8
com.github.axet
kaptcha
0.0.9
junit
junit
3.8.1
test