本文整理了Java中com.google.code.kaptcha.Producer.createImage()
方法的一些代码示例,展示了Producer.createImage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Producer.createImage()
方法的具体详情如下:
包路径:com.google.code.kaptcha.Producer
类名称:Producer
方法名:createImage
[英]Create an image which will have written a distorted text.
[中]创建一个将书写扭曲文本的图像。
代码示例来源:origin: stylefeng/Guns
BufferedImage bi = producer.createImage(capText);
ServletOutputStream out = null;
try {
代码示例来源:origin: timebusker/spring-boot
/**
* 获取验证码
*
* @throws CommonException
* @throws IOException
*/
@RequestMapping("/authcode")
public void captcha() throws CommonException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, text);
// 输出验证码图片到页面
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: pig4cloud/pig
/**
* 创建验证码
*
* @param request request
* @throws Exception
*/
@GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
public void createCode(@PathVariable String randomStr, HttpServletRequest request, HttpServletResponse response)
throws Exception {
Assert.isBlank(randomStr, "机器码不能为空");
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
userService.saveImageCode(randomStr, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: com.github.livesense/org.liveSense.service.captcha
@Override
public BufferedImage getImage(String id, String text, Locale locale) {
// create the text for the image
String capText = this.kaptchaProducer.createText();
codeTexts.put(id, capText);
return this.kaptchaProducer.createImage(capText);
}
代码示例来源:origin: com.github.livesense/org.liveSense.service.captcha
@Override
public BufferedImage getImage(String id, String text, Locale locale) {
// create the text for the image
String capText = this.kaptchaProducer.createText();
codeTexts.put(id, capText);
return this.kaptchaProducer.createImage(capText);
}
代码示例来源:origin: muyinchen/migo-security
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
}
代码示例来源:origin: zhaoqicheng/renren-fast
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: opplus/springboot-admin
@RequestMapping("/captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: tumao2/hdw-dubbo
@GetMapping("captcha.jpg")
public void kaptcha(HttpServletResponse response, String uuid) throws IOException {
logger.info("前台请求的UUID:" + uuid);
if (StringUtils.isBlank(uuid)) {
throw new RuntimeException("uuid不能为空");
}
//生成文字验证码
String code = producer.createText();
redisService.set(uuid, code);
response.setHeader("Cache-Control", "no-store,no-cache");
response.setContentType("image/jpeg");
BufferedImage image = producer.createImage(code);
ServletOutputStream outputStream = response.getOutputStream();
ImageIO.write(image, "jpg", outputStream);
IOUtils.closeQuietly(outputStream);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core
@NoRequestLogging
@GetMapping("/captcha.jpg")
public void captcha(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到 session
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
}
}
代码示例来源:origin: liuweijw/fw-cloud-framework
/**
* 创建验证码
*/
@GetMapping(SecurityConstant.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
public void createCode(@PathVariable String randomStr, HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
// 生成文字验证码
String text = producer.createText();
// 生成图片验证码
BufferedImage image = producer.createImage(text);
userService.saveImageCode(randomStr, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: yzcheng90/X-SpringBoot
/**
* 验证码
*/
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
代码示例来源:origin: FenixEdu/fenixedu-academic
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setHeader("Cache-Control", "no-store, no-cache");
// return a jpeg
response.setContentType("image/jpeg");
// create the text for the image
String capText = kaptchaProducer.createText();
// create the image with the text
BufferedImage bi = kaptchaProducer.createImage(capText);
try (ServletOutputStream out = response.getOutputStream()) {
// write the data out
ImageIO.write(bi, "jpg", out);
request.getSession().setAttribute(KAPTCHA_SESSION_KEY, new KaptchaSession(capText));
return null;
}
}
代码示例来源:origin: com.github.axet/kaptcha
BufferedImage bi = this.kaptchaProducer.createImage(capText);
代码示例来源:origin: com.wuyushuo/vplus-data
public static void producerCaptcha(Producer captchaProducer, HttpServletRequest request, HttpServletResponse response, String captchaKey) throws Exception {
if(null == captchaProducer || null == request || null == response){
throw new NullPointerException("系统参数没有实例化");
}
HttpSession session = request.getSession();
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
String capText = captchaProducer.createText();
String sessionKey = captchaKey(captchaKey);
log.debug("[captcha] key:{}, value", sessionKey, capText);
session.setAttribute(sessionKey, capText);
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
}
代码示例来源:origin: com.github.vindell/spring-boot-starter-kaptcha
/** */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Set to expire far in the past.
resp.setDateHeader("Expires", 0);
// Set standard HTTP/1.1 no-cache headers.
resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
resp.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
resp.setHeader("Pragma", "no-cache");
// return a jpeg
resp.setContentType("image/jpeg");
// create the text for the image
String capText = this.kaptchaProducer.createText();
this.captchaResolver.setCaptcha(req, resp, capText, new Date());
// create the image with the text
BufferedImage bi = this.kaptchaProducer.createImage(capText);
ServletOutputStream out = resp.getOutputStream();
// write the data out
ImageIO.write(bi, "jpg", out);
}
}
代码示例来源:origin: jtalks-org/jcommune
/**
* Refresh captcha image on registration form.
*
* @param request http request
* @param response http response
* @throws IOException
*/
public void refreshCaptchaImage(HttpServletRequest request, HttpServletResponse response)
throws IOException {
ServletOutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
String capText = getCaptchaProducer().createText();
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
BufferedImage bi = getCaptchaProducer().createImage(capText);
ImageIO.write(bi, "jpg", out);
out.flush();
}
代码示例来源:origin: liuht777/Taroco
/**
* 创建验证码
*
* @throws Exception
*/
@GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
public void createCode(@PathVariable String randomStr, HttpServletResponse response)
throws Exception {
Assert.notEmpty(randomStr, "机器码不能为空");
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
userService.saveImageCode(randomStr, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
IOUtils.closeQuietly(out);
}
}
代码示例来源:origin: yjjdick/sdb-mall
@Override
public BufferedImage getCaptcha(String uuid) {
if(StringUtils.isBlank(uuid)){
throw new RRException("uuid不能为空");
}
//生成文字验证码
String code = producer.createText();
SysCaptcha captcha = new SysCaptcha();
captcha.setUuid(uuid);
captcha.setCode(code);
//5分钟后过期
captcha.setExpireTime(DateUtils.addDateMinutes(new Date(), 5));
captcha.save();
return producer.createImage(code);
}
代码示例来源:origin: tigerphz/tgcloud-master
/**
* 生成图片验证码.
*
* @param request the request
* @return the image code
*/
@Override
public ImageCode generate(ServletWebRequest request) {
String kaptchaCode = captchaProducer.createText();
BufferedImage image = captchaProducer.createImage(kaptchaCode);
return new ImageCode(image, kaptchaCode, securityProperties.getCode().getImage().getExpireIn());
}
内容来源于网络,如有侵权,请联系作者删除!