Skip to content

Commit 55124d2

Browse files
authored
Merge pull request #2 from onixbyte/release/v1.0.0
Release/v1.0.0
2 parents 7366860 + 3f02d45 commit 55124d2

File tree

7 files changed

+48
-46
lines changed

7 files changed

+48
-46
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ http-client.private.env.json
106106
gradle-app.setting
107107

108108
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
109-
!gradle-wrapper.jar
109+
!/gradle/wrapper/gradle-wrapper.jar
110110

111111
# Avoid ignore Gradle wrappper properties
112112
!gradle-wrapper.properties
@@ -134,13 +134,14 @@ gradle-app.setting
134134
.mtj.tmp/
135135

136136
# Package Files #
137-
*.jar
138137
*.war
139138
*.nar
140139
*.ear
141140
*.zip
142141
*.tar.gz
143142
*.rar
143+
*.jar
144+
!/gradle/wrapper/gradle-wrapper.jar
144145

145146
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
146147
hs_err_pid*

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,47 @@ import com.onixbyte.captcha.noise.NoiseProducer;
5252
import com.onixbyte.captcha.noise.impl.DefaultNoiseProducer;
5353
import com.onixbyte.captcha.text.TextProducer;
5454
import com.onixbyte.captcha.text.WordRenderer;
55-
import com.onixbyte.captcha.text.impl.DefaultTextCreator;
55+
import com.onixbyte.captcha.text.impl.DefaultTextProducer;
5656
import com.onixbyte.captcha.text.impl.DefaultWordRenderer;
5757

5858
import javax.imageio.ImageIO;
5959
import java.awt.*;
6060
import java.awt.image.BufferedImage;
6161
import java.io.File;
6262
import java.io.IOException;
63-
import java.util.Collections;
6463

6564
public class CaptchaExample {
6665

6766
public static void main(String[] args) throws IOException {
6867
// Define producers and engines
69-
TextProducer textProducer = new DefaultTextCreator();
70-
WordRenderer wordRenderer = new DefaultWordRenderer(
71-
Color.BLACK,
72-
Collections.singletonList(new Font("Arial", Font.BOLD, 40))
73-
);
74-
GimpyEngine gimpyEngine = new WaterRipple(new DefaultNoiseProducer());
75-
BackgroundProducer backgroundProducer = new DefaultBackgroundProducer(
76-
Color.WHITE,
77-
Color.LIGHT_GRAY
78-
);
79-
NoiseProducer noiseProducer = new DefaultNoiseProducer();
68+
TextProducer textProducer = DefaultTextProducer.builder()
69+
// .length(6) // default length is 6
70+
// .chars("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) // default available characters are 'a' to 'z', 'A' to 'Z' and '0' - '9'
71+
.build();
72+
WordRenderer wordRenderer = DefaultWordRenderer.builder()
73+
// .fontColour(Color.BLACK) // default to Color.BLACK
74+
// .fonts(new Font("Arial", Font.BOLD, 40)) // default to (Arial Bold 40) and (Courier, Bold, 40)
75+
// .fontSize(40) // default to 40
76+
// .charSpace(2) // default to 2
77+
.build();
78+
NoiseProducer noiseProducer = DefaultNoiseProducer.builder()
79+
// .noiseColour(Color.BLACK) // default to Color.BLACK
80+
.build();
81+
GimpyEngine gimpyEngine = WaterRipple.builder()
82+
// .noiseProducer(DefaultNoiseProducer.builder().build()) // default to DefaultNoiseProducer with default configurations
83+
.build();
84+
BackgroundProducer backgroundProducer = DefaultBackgroundProducer.builder()
85+
// .colourFrom(Color.WHITE) // default to Color.LIGHT_GRAY
86+
// .colourTo(Color.LIGHT_GRAY) // default to Color.WHITE
87+
.build();
8088

8189
// Create a CAPTCHA producer
82-
Producer captcha = new DefaultCaptchaProducer(
83-
wordRenderer,
84-
gimpyEngine,
85-
backgroundProducer,
86-
200,
87-
50,
88-
true,
89-
Color.BLACK,
90-
1,
91-
textProducer
92-
);
90+
Producer captcha = DefaultCaptchaProducer.builder()
91+
.textProducer(textProducer) // default to DefaultTextProducer with default configurations
92+
.wordRenderer(wordRenderer) // default to DefaultWordRenderer with default configurations
93+
.gimpyEngine(gimpyEngine) // default to WaterRipple with default configurations
94+
.backgroundProducer(backgroundProducer) // default to DefaultBackgroundProducer with default configurations
95+
.build();
9396

9497
// Generate text and create the image
9598
String captchaText = captcha.createText();

gradle/wrapper/gradle-wrapper.jar

59.3 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#Sun Oct 26 12:17:38 CST 2025
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip

src/main/java/com/onixbyte/captcha/impl/DefaultCaptchaProducer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.onixbyte.captcha.gimpy.impl.WaterRipple;
3030
import com.onixbyte.captcha.text.TextProducer;
3131
import com.onixbyte.captcha.text.WordRenderer;
32-
import com.onixbyte.captcha.text.impl.DefaultTextCreator;
32+
import com.onixbyte.captcha.text.impl.DefaultTextProducer;
3333
import com.onixbyte.captcha.text.impl.DefaultWordRenderer;
3434

3535
import java.awt.BasicStroke;
@@ -192,14 +192,14 @@ public static class DefaultCaptchaProducerBuilder {
192192

193193
private DefaultCaptchaProducerBuilder() {
194194
this.wordRenderer = DefaultWordRenderer.builder().build();
195-
this.gimpyEngine = (GimpyEngine) WaterRipple.builder().build();
195+
this.gimpyEngine = WaterRipple.builder().build();
196196
this.backgroundProducer = DefaultBackgroundProducer.builder().build();
197197
this.width = 200;
198198
this.height = 50;
199199
this.borderDrawn = true;
200200
this.borderColour = Color.BLACK;
201201
this.borderThickness = 1;
202-
this.textProducer = DefaultTextCreator.builder().build();
202+
this.textProducer = DefaultTextProducer.builder().build();
203203
}
204204

205205
/**

src/main/java/com/onixbyte/captcha/noise/impl/NoNoiseProducer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package com.onixbyte.captcha.noise.impl;
2424

2525
import com.onixbyte.captcha.noise.NoiseProducer;
26-
import com.onixbyte.captcha.text.impl.DefaultTextCreator;
2726

2827
import java.awt.image.BufferedImage;
2928

src/main/java/com/onixbyte/captcha/text/impl/DefaultTextCreator.java renamed to src/main/java/com/onixbyte/captcha/text/impl/DefaultTextProducer.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
/**
3232
* The default implementation of {@link TextProducer}.
3333
*/
34-
public class DefaultTextCreator implements TextProducer {
34+
public class DefaultTextProducer implements TextProducer {
3535

3636
private final int length;
3737

3838
private final char[] chars;
3939

40-
private DefaultTextCreator(int length, char[] chars) {
40+
private DefaultTextProducer(int length, char[] chars) {
4141
this.length = length;
4242
this.chars = chars;
4343
}
@@ -58,22 +58,22 @@ public String getText() {
5858
}
5959

6060
/**
61-
* Creates a new {@link DefaultTextCreatorBuilder}.
61+
* Creates a new {@link DefaultTextProducerBuilder}.
6262
*
63-
* @return a new {@link DefaultTextCreatorBuilder}
63+
* @return a new {@link DefaultTextProducerBuilder}
6464
*/
65-
public static DefaultTextCreatorBuilder builder() {
66-
return new DefaultTextCreatorBuilder();
65+
public static DefaultTextProducerBuilder builder() {
66+
return new DefaultTextProducerBuilder();
6767
}
6868

6969
/**
70-
* A builder for creating {@link DefaultTextCreator} instances.
70+
* A builder for creating {@link DefaultTextProducer} instances.
7171
*/
72-
public static class DefaultTextCreatorBuilder {
72+
public static class DefaultTextProducerBuilder {
7373
private int length;
7474
private char[] chars;
7575

76-
private DefaultTextCreatorBuilder() {
76+
private DefaultTextProducerBuilder() {
7777
this.length = 6;
7878
this.chars = new char[]{
7979
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
@@ -89,7 +89,7 @@ private DefaultTextCreatorBuilder() {
8989
* @param length the length
9090
* @return this builder
9191
*/
92-
public DefaultTextCreatorBuilder length(int length) {
92+
public DefaultTextProducerBuilder length(int length) {
9393
if (length <= 0) {
9494
throw new IllegalArgumentException("Length should be greater than 0.");
9595
}
@@ -103,7 +103,7 @@ public DefaultTextCreatorBuilder length(int length) {
103103
* @param chars the characters
104104
* @return this builder
105105
*/
106-
public DefaultTextCreatorBuilder chars(char[] chars) {
106+
public DefaultTextProducerBuilder chars(char[] chars) {
107107
if (Objects.isNull(chars) || chars.length == 0) {
108108
throw new IllegalArgumentException("Chars cannot be empty.");
109109
}
@@ -112,12 +112,12 @@ public DefaultTextCreatorBuilder chars(char[] chars) {
112112
}
113113

114114
/**
115-
* Builds a new {@link DefaultTextCreator} with the configured properties.
115+
* Builds a new {@link DefaultTextProducer} with the configured properties.
116116
*
117-
* @return a new {@link DefaultTextCreator}
117+
* @return a new {@link DefaultTextProducer}
118118
*/
119-
public DefaultTextCreator build() {
120-
return new DefaultTextCreator(length, chars);
119+
public DefaultTextProducer build() {
120+
return new DefaultTextProducer(length, chars);
121121
}
122122
}
123123
}

0 commit comments

Comments
 (0)