mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
Java formatter
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
3682b2cb7d
commit
8ea0652331
@ -36,16 +36,18 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
|||||||
advances.add(currX);
|
advances.add(currX);
|
||||||
currX += font.getStringBounds(String.valueOf(c), frc).getWidth();
|
currX += font.getStringBounds(String.valueOf(c), frc).getWidth();
|
||||||
currX += spacing;
|
currX += spacing;
|
||||||
};
|
}
|
||||||
|
;
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
return advances.toArray(new Integer[]{});
|
return advances.toArray(new Integer[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage makeImage(final Consumer<Graphics2D> f) {
|
private BufferedImage makeImage(final Consumer<Graphics2D> f) {
|
||||||
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
final var graphics2D = img.createGraphics();
|
final var graphics2D = img.createGraphics();
|
||||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
graphics2D.setRenderingHint(
|
||||||
|
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
graphics2D.setFont(font);
|
graphics2D.setFont(font);
|
||||||
f.accept(graphics2D);
|
f.accept(graphics2D);
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
@ -63,21 +65,32 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
|||||||
final var writer = new GifSequenceWriter(output, 1, 900, true);
|
final var writer = new GifSequenceWriter(output, 1, 900, true);
|
||||||
final var advances = computeOffsets(text);
|
final var advances = computeOffsets(text);
|
||||||
final var prevColor = Color.getHSBColor(0f, 0f, 0.1f);
|
final var prevColor = Color.getHSBColor(0f, 0f, 0.1f);
|
||||||
IntStream.range(0, text.length()).forEach(i -> {
|
IntStream.range(0, text.length())
|
||||||
final var color = Color.getHSBColor(HelperFunctions.randomNumber(0, 100)/100.0f, 0.6f, 1.0f);
|
.forEach(
|
||||||
final var prevI = (i - 1 + text.length()) % text.length();
|
i -> {
|
||||||
final var nextImage = makeImage((g) -> {
|
final var color =
|
||||||
g.setColor(prevColor);
|
Color.getHSBColor(HelperFunctions.randomNumber(0, 100) / 100.0f, 0.6f, 1.0f);
|
||||||
g.drawString(String.valueOf(text.charAt(prevI)), advances[prevI] + jitter(), 45 + jitter());
|
final var prevI = (i - 1 + text.length()) % text.length();
|
||||||
g.setColor(color);
|
final var nextImage =
|
||||||
g.drawString(String.valueOf(text.charAt(i)), advances[i] + jitter(), 45 + jitter());
|
makeImage(
|
||||||
});
|
(g) -> {
|
||||||
try {
|
g.setColor(prevColor);
|
||||||
writer.writeToSequence(nextImage);
|
g.drawString(
|
||||||
} catch (final IOException e) {
|
String.valueOf(text.charAt(prevI)),
|
||||||
e.printStackTrace();
|
advances[prevI] + jitter(),
|
||||||
}
|
45 + jitter());
|
||||||
});
|
g.setColor(color);
|
||||||
|
g.drawString(
|
||||||
|
String.valueOf(text.charAt(i)),
|
||||||
|
advances[i] + jitter(),
|
||||||
|
45 + jitter());
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
writer.writeToSequence(nextImage);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
writer.close();
|
writer.close();
|
||||||
output.close();
|
output.close();
|
||||||
return byteArrayOutputStream.toByteArray();
|
return byteArrayOutputStream.toByteArray();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user