Detected code, here are some useful tools:
Formatted code
package Captcha;
import Utils.CustomFont;
import java.awt. * ;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
public class CaptchaGenerator {
private static final int WIDTH = 200;
private static final int HEIGHT = 50;
private static final int FONT_SIZE = 30;
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final Random random = new Random();
public final static Font font;
static {
try {
font = CustomFont.getFont("DejaVuSans.ttf", Font.BOLD);
} catch (IOException | FontFormatException e) {
throw new RuntimeException(e);
}
}
public static BufferedImage generateCaptchaImage(String captchaText) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, WIDTH, HEIGHT);
graphics.setColor(Color.BLACK);
// Font font = new Font("Dialog", Font.PLAIN, FONT_SIZE);
// graphics.setFont(font);
graphics.drawString(captchaText, 50, 35);
return image;
}
public static String generateRandomText(int length) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
int index = random.nextInt(CHARACTERS.length());
sb.append(CHARACTERS.charAt(index));
}
return sb.toString();
}
}