提交 d6a1528c 编写于 作者: dong.an's avatar dong.an

图形验证码

上级 bf26aa0e
流水线 #13077 已失败 于阶段
...@@ -29,11 +29,11 @@ public class CaptchaGenerator { ...@@ -29,11 +29,11 @@ public class CaptchaGenerator {
public CaptchaGenerator() throws FontFormatException, IOException { public CaptchaGenerator() throws FontFormatException, IOException {
int h = 40; int h = 40;
ctxs.put(Range.closedOpen(0, h), new CaptchaContext(h * 4, h, h / 5 * 4, true)); ctxs.put(Range.closedOpen(0, h), new CaptchaContext(h * 4, h, (h / 2) * 3, true));
h *= 2; h *= 2;
ctxs.put(Range.closedOpen(h / 2, h), new CaptchaContext(h * 4, h, h / 5 * 4, true)); ctxs.put(Range.closedOpen(h / 2, h), new CaptchaContext(h * 4, h, (h / 2) * 3, true));
h *= 2; h *= 2;
ctxs.put(Range.closedOpen(h / 2, Integer.MAX_VALUE), new CaptchaContext(h * 4, h, h / 5 * 4, true)); ctxs.put(Range.closedOpen(h / 2, Integer.MAX_VALUE), new CaptchaContext(h * 4, h, (h / 2) * 3, true));
gens.add(new NumberLetterGenerator()); gens.add(new NumberLetterGenerator());
} }
......
/**
*
*/
package com.pica.cloud.account.account.server.util.captcha; package com.pica.cloud.account.account.server.util.captcha;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.UUID; import java.util.UUID;
...@@ -63,8 +58,8 @@ public class CaptchaUtil { ...@@ -63,8 +58,8 @@ public class CaptchaUtil {
//} //}
ctx.height = image.getHeight(); ctx.height = image.getHeight();
int charMaxWidth = (int) ((image.getWidth() * 0.7) / text.length); int charMaxWidth = (int) ((image.getWidth() * 0.8) / text.length);
int xPos = (int) (image.getWidth() * 0.15); int xPos = (int) (image.getWidth() * 0.1);
for (char ch : text) { for (char ch : text) {
drawCharacter(g2d, ctx, ch, xPos, charMaxWidth); drawCharacter(g2d, ctx, ch, xPos, charMaxWidth);
xPos += charMaxWidth; xPos += charMaxWidth;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册