jcaptcha进阶
1.改动CaptchaServiceSingleton类。使用带參构造方法来创建DefaultManageableImageCaptchaService对象。
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">
package com.xhc.jcaptcha; import com.octo.captcha.service.captchastore.FastHashMapCaptchaStore;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
import com.octo.captcha.service.image.ImageCaptchaService; public class CaptchaServiceSingleton {
private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService(new FastHashMapCaptchaStore(), new MyImageEngine(), 180,
100000, 75000);
public static ImageCaptchaService getInstance(){
return instance;
}
}
2.MyImageEngine类
package com.xhc.jcaptcha;
import java.awt.Color;
import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.LineRandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.FileDictionary;
import com.octo.captcha.component.word.wordgenerator.ComposeDictionaryWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;
public class MyImageEngine extends ListImageCaptchaEngine {
@Override
protected void buildInitialFactories() {
WordGenerator dictionnaryWords = new ComposeDictionaryWordGenerator(
new FileDictionary("toddlist"));
/* //BaffleRandomTextPaster类生成的是带干扰点的随机验证码贴纸,这里表示最少4个,最多5个字母。蓝色。1个干扰点,干扰点为黄色
TextPaster randomPaster = new BaffleRandomTextPaster(new Integer(4),
new Integer(5), Color.blue, new Integer(1), Color.yellow);*/
//LineRandomTextPaster类生成的是带干扰线的随机验证码贴纸。。。
TextPaster randomPaster = new LineRandomTextPaster(new Integer(4),
new Integer(5),Color.blue, new Integer(1),Color.pink); /*//背景大小及样式设置,UniColorBackgroundGenerator类生成的是统一背景。这里背景统一是lightGray颜色
//宽度为180,高度为50。 BackgroundGenerator back = new UniColorBackgroundGenerator(new Integer(
180), new Integer(50), Color.lightGray);*/
/* //FunkyBackgroundGenerator类生成的是炫酷背景
BackgroundGenerator back = new FunkyBackgroundGenerator(new Integer(
180), new Integer(50));*/
//GradientBackgroundGenerator类生成的是颜色渐变的背景
BackgroundGenerator back = new GradientBackgroundGenerator(new Integer(
180), new Integer(50),Color.gray,Color.yellow); /* //字体设置,RandomFontGenerator类生成的是随机字体,这里字体最小为25px,最大为30px
FontGenerator shearedFont = new RandomFontGenerator(new Integer(25),
new Integer(30));*/
//TwistedRandomFontGenerator类生成扭曲的字体
FontGenerator shearedFont = new TwistedRandomFontGenerator(new Integer(25),
new Integer(30)); //生成验证码模板图片
WordToImage word2image = new ComposedWordToImage(shearedFont, back,
randomPaster); //把随机生成的验证码和模板放入工厂进行组装生成终于的验证码图片
addFactory(new GimpyFactory(dictionnaryWords, word2image));
}
}
3.jsp代码。web.xml配置,以及登陆校验的servlet与前一遍文章使用jcaptcha插件生成验证码代码一样。能够跳转到那里去查看代码。
4.效果图
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">
jcaptcha进阶的更多相关文章
- nodejs进阶(6)—连接MySQL数据库
1. 建库连库 连接MySQL数据库需要安装支持 npm install mysql 我们需要提前安装按mysql sever端 建一个数据库mydb1 mysql> CREATE DATABA ...
- nodejs进阶(4)—读取图片到页面
我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...
- JavaScript进阶之路(一)初学者的开始
一:写在前面的问题和话 一个javascript初学者的进阶之路! 背景:3年后端(ASP.NET)工作经验,javascript水平一般般,前端水平一般般.学习资料:犀牛书. 如有误导,或者错误的地 ...
- nodejs进阶(3)—路由处理
1. url.parse(url)解析 该方法将一个URL字符串转换成对象并返回. url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) ...
- nodejs进阶(5)—接收请求参数
1. get请求参数接收 我们简单举一个需要接收参数的例子 如果有个查找功能,查找关键词需要从url里接收,http://localhost:8000/search?keyword=地球.通过前面的进 ...
- nodejs进阶(1)—输出hello world
下面将带领大家一步步学习nodejs,知道怎么使用nodejs搭建服务器,响应get/post请求,连接数据库等. 搭建服务器页面输出hello world var http = require ...
- [C#] 进阶 - LINQ 标准查询操作概述
LINQ 标准查询操作概述 序 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了IEnumerable<T> ...
- Java 进阶 hello world! - 中级程序员之路
Java 进阶 hello world! - 中级程序员之路 Java是一种跨平台的语言,号称:"一次编写,到处运行",在世界编程语言排行榜中稳居第二名(TIOBE index). ...
- C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解 ...
随机推荐
- python3:语法变动 及新特性
python3.0 对python2.x 升级后重大语法变动,幸好留下2.7.6及后续2版本,保持一些语法兼容. 原始地址:http://hi.baidu.com/jxq61/item/3a24883 ...
- C#异步Async、Task、Await
参考http://www.cnblogs.com/jesse2013/p/async-and-await.html 事例: static void Main(string[] args) { ; i ...
- https ssl 总结
主要工作: 1)算法协商: 2)密钥交换: 3)身份认证: 4)数据通信: 1.2.3主要使用握手协议: 4使用记录协议. SSL协议可分为两层:记录协议.握手协议 SSL Record Protoc ...
- PyCharm 恢复默认设置 | JetBrains IDE 配置文件安装目录
网上的答案为什么都乱七八糟并且全都全篇一律?某度知道是发源地? 先说 Mac 按需运行下面的 rm 删除命令 # Configuration rm -rf ~/Library/Preferences/ ...
- BZOJ 4327: JSOI2012 玄武密码 后缀自动机
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) # ...
- Python 集合 day3
集合(set)是一个无序的不重复元素序列. 可以使用大括号 { } 或者 set() 函数创建集合,集合用{},里面是一个一个元素,不同于key-value形式的字典: 注意:创建一个空集合必须用 s ...
- PHP 设计模式之工厂模式 (静态工厂模式)
### 工厂模式: 由工厂类根据参数来决定创建出哪一种产品类的实例.工厂类是指包含了一个专门用来创建其他对象的方法的类.所谓按需分配,传入参数进行选择,返回具体的类.工厂模式的最主要作用就是对象创建的 ...
- Git 基础教程 之 从远程库克隆
③ 克隆一个本地仓库 a, 在合适的地方,在Git Bash下执行命令: git clone git@github.com:hardy9sap/gittutorial.git
- Codeforces 912A/B
A. Tricky Alchemy 传送门:http://codeforces.com/contest/912/problem/A 参考程序如下: #include <stdio.h> # ...
- jQuery Webcam Plugin jscam.swf文件反编译工具使用说明
jQuery webcam plugin是一个在ie,firefox,chrome下都可以用的摄像头摄像及拍照用的插件. (http://www.xarg.org/project/jquery-web ...