Captcha API
Package Overview
The library is organised under the base package com.onixbyte.captcha with the following structure:
Producer
The top-level interface responsible for creating CAPTCHA images with text drawn on them.
Producer captcha = DefaultCaptchaProducer.builder()
.textProducer(textProducer)
.wordRenderer(wordRenderer)
.gimpyEngine(gimpyEngine)
.backgroundProducer(backgroundProducer)
.width(200)
.height(50)
.borderDrawn(true)
.borderColour(Color.BLACK)
.borderThickness(1)
.build();
String text = captcha.createText();
BufferedImage image = captcha.createImage(text);
DefaultCaptchaProducer Builder
Text
TextProducer
Interface for creating CAPTCHA text strings.
public interface TextProducer {
String getText();
}
DefaultTextProducer
Generates random text with configurable length and character set.
DefaultTextProducer textProducer = DefaultTextProducer.builder()
.length(6) // default: 6
.chars("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) // default: a-z, A-Z, 0-9
.build();
WordRenderer
Interface for rendering text onto an image.
public interface WordRenderer {
BufferedImage renderWord(String word, int width, int height);
}
DefaultWordRenderer
Renders text with configurable font, colour, and spacing.
DefaultWordRenderer wordRenderer = DefaultWordRenderer.builder()
.fontSize(40) // default: 40
.fonts("Arial", "Courier") // default: Arial, Courier
.fontColour(Color.BLACK) // default: Color.BLACK
.charSpace(2) // default: 2
.fontStyle(FontStyle.BOLD) // default: FontStyle.BOLD
.build();
FontStyle
Defines the supported font styles for rendering CAPTCHA text.
GimpyEngine
Interface for applying image distortion effects.
public interface GimpyEngine {
BufferedImage getDistortedImage(BufferedImage baseImage);
}
WaterRipple
Applies a water ripple distortion effect. Extends AbstractGimpyEngine and adds noise automatically.
WaterRipple gimpy = WaterRipple.builder()
.noiseProducer(DefaultNoiseProducer.builder().build()) // default: DefaultNoiseProducer
.build();
FishEyeGimpy
Applies a fish-eye distortion effect with horizontal and vertical lines over the image.
FishEyeGimpy gimpy = FishEyeGimpy.builder()
.build();
ShadowGimpy
Applies a shadow and ripple effect. Extends AbstractGimpyEngine and adds noise automatically.
ShadowGimpy gimpy = ShadowGimpy.builder()
.noiseProducer(DefaultNoiseProducer.builder().build()) // default: DefaultNoiseProducer
.build();
Noise
NoiseProducer
Interface for adding noise to an image.
public interface NoiseProducer {
void makeNoise(BufferedImage image, float factorOne, float factorTwo,
float factorThree, float factorFour);
}
DefaultNoiseProducer
Adds noise curves with configurable colour.
DefaultNoiseProducer noise = DefaultNoiseProducer.builder()
.noiseColour(Color.BLACK) // default: Color.BLACK
.build();
NoNoiseProducer
A no-op implementation that does not add any noise to the image.
NoiseProducer noise = NoNoiseProducer.builder()
.build();
Background
BackgroundProducer
Interface for adding background to an image.
public interface BackgroundProducer {
BufferedImage addBackground(BufferedImage image);
}
DefaultBackgroundProducer
Creates a gradient background with configurable start and end colours.
DefaultBackgroundProducer background = DefaultBackgroundProducer.builder()
.colourFrom(Color.WHITE) // default: Color.LIGHT_GRAY
.colourTo(Color.LIGHT_GRAY) // default: Color.WHITE
.build();