feat: change the verify code image size to 240x80

This commit is contained in:
wzp 2024-12-24 16:24:59 +08:00
parent 786eef1a63
commit 831ae448cf
2 changed files with 12 additions and 7 deletions

View File

@ -186,7 +186,6 @@ public class UserServices {
public Result<VerifyCodeResponse> getVerifyCode() {
VerifyCodeResponse verifyCodeResponse = verifyCodeUtils.generateVerifyCode();
//TODO ERROR CANNOT CREATE RESPONSE BODY
return Result.success(verifyCodeResponse);
}

View File

@ -20,14 +20,19 @@ import java.util.Random;
@Component
@RequiredArgsConstructor
public class VerifyCodeUtils {
public static final int width = 120;
public static final int height = 40;
public static final int fontSize = 25;
public static final int width = 240;
public static final int height = 80;
public static final int fontSize = 50;
public static final Font mainFont = new Font("宋体", Font.BOLD, fontSize);
private final RandomUtils randomUtils;
private final VerifyDao verifyDao;
private void setToRandomColor(Graphics g) {
Random random = new Random();
g.setColor(new Color(20 + random.nextInt(120), 20 + random.nextInt(120), 20 + random.nextInt(120)));
}
@SneakyThrows
public VerifyCodeResponse generateVerifyCode() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
@ -37,9 +42,10 @@ public class VerifyCodeUtils {
int x = 0;
for (char c : text.toCharArray()) {
Random random = new Random();
g.setColor(new Color(20 + random.nextInt(120), 20 + random.nextInt(120), 20 + random.nextInt(120)));
g.drawString(c + "", 15 + x * 20, 20 + new Random().nextInt(10));
for (int j = 0; j < random.nextInt(1, 5); j++) {
setToRandomColor(g);
g.drawString(c + "", 15 + x * 40, 40 + new Random().nextInt(10));
for (int j = 0; j < random.nextInt(3, 7); j++) {
setToRandomColor(g);
g.drawLine(random.nextInt(width), random.nextInt(height), random.nextInt(width), random.nextInt(height));
}
x++;