mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-11-29 05:18:50 -05:00
each challenge provider now respects the size parameter when construction image
This commit is contained in:
@@ -45,14 +45,14 @@ class DebugCaptcha extends ChallengeProvider {
|
||||
matches
|
||||
}
|
||||
|
||||
private def simpleText(text: String): Array[Byte] = {
|
||||
val img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB)
|
||||
private def simpleText(width: Int, height: Int, text: String): Array[Byte] = {
|
||||
val img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
||||
val font = new Font("Arial", Font.ROMAN_BASELINE, 56)
|
||||
val graphics2D = img.createGraphics()
|
||||
val textLayout = new TextLayout(text, font, graphics2D.getFontRenderContext())
|
||||
HelperFunctions.setRenderingHints(graphics2D)
|
||||
graphics2D.setPaint(Color.WHITE)
|
||||
graphics2D.fillRect(0, 0, 350, 100)
|
||||
graphics2D.fillRect(0, 0, width, height)
|
||||
graphics2D.setPaint(Color.BLACK)
|
||||
textLayout.draw(graphics2D, 15, 50)
|
||||
graphics2D.dispose()
|
||||
@@ -68,6 +68,9 @@ class DebugCaptcha extends ChallengeProvider {
|
||||
|
||||
def returnChallenge(level: String, size: String): Challenge = {
|
||||
val secret = HelperFunctions.randomString(6, HelperFunctions.safeAlphabets)
|
||||
new Challenge(simpleText(secret), "image/png", secret.toLowerCase())
|
||||
val size2D = HelperFunctions.parseSize2D(size)
|
||||
val width = size2D(0)
|
||||
val height = size2D(1)
|
||||
new Challenge(simpleText(width, height, secret), "image/png", secret.toLowerCase())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import lc.captchas.interfaces.Challenge
|
||||
import java.util.{List => JavaList, Map => JavaMap}
|
||||
import java.io.ByteArrayOutputStream
|
||||
import lc.misc.PngImageWriter
|
||||
import lc.misc.HelperFunctions
|
||||
|
||||
class FilterChallenge extends ChallengeProvider {
|
||||
def getId = "FilterChallenge"
|
||||
@@ -35,7 +36,10 @@ class FilterChallenge extends ChallengeProvider {
|
||||
val alphabet = "abcdefghijklmnopqrstuvwxyz"
|
||||
val n = 8
|
||||
val secret = LazyList.continually(r.nextInt(alphabet.size)).map(alphabet).take(n).mkString
|
||||
val canvas = new BufferedImage(225, 50, BufferedImage.TYPE_INT_RGB)
|
||||
val size2D = HelperFunctions.parseSize2D(size)
|
||||
val width = size2D(0)
|
||||
val height = size2D(1)
|
||||
val canvas = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
||||
val g = canvas.createGraphics()
|
||||
g.setColor(Color.WHITE)
|
||||
g.fillRect(0, 0, canvas.getWidth, canvas.getHeight)
|
||||
|
||||
@@ -11,6 +11,7 @@ import lc.captchas.interfaces.ChallengeProvider
|
||||
import lc.captchas.interfaces.Challenge
|
||||
import lc.misc.GifSequenceWriter
|
||||
import java.util.{List => JavaList, Map => JavaMap}
|
||||
import lc.misc.HelperFunctions
|
||||
|
||||
class Drop {
|
||||
var x = 0
|
||||
@@ -59,8 +60,9 @@ class RainDropsCP extends ChallengeProvider {
|
||||
def returnChallenge(level: String, size: String): Challenge = {
|
||||
val r = new scala.util.Random
|
||||
val secret = LazyList.continually(r.nextInt(alphabet.size)).map(alphabet).take(n).mkString
|
||||
val width = 450
|
||||
val height = 100
|
||||
val size2D = HelperFunctions.parseSize2D(size)
|
||||
val width = size2D(0)
|
||||
val height = size2D(1)
|
||||
val imgType = BufferedImage.TYPE_INT_RGB
|
||||
val xOffset = 2 + r.nextInt(3)
|
||||
val xBias = (height / 10) - 2
|
||||
|
||||
Reference in New Issue
Block a user