Class CaptchaConfig

java.lang.Object
cloud.opencode.base.captcha.CaptchaConfig

public final class CaptchaConfig extends Object
Captcha Configuration - Configuration for CAPTCHA generation 验证码配置 - 验证码生成配置

This class provides a fluent builder API for configuring CAPTCHA generation.

此类提供用于配置验证码生成的流式构建器 API。

Features | 主要功能:

  • Fluent builder API for configuration - 流式构建器 API 配置
  • Default values for all settings - 所有设置的默认值
  • Support for image dimensions, fonts, noise, and expiration - 支持图像尺寸、字体、噪点和过期
  • GIF animation settings (frame count, delay) - GIF 动画设置(帧数、延迟)

Usage Examples | 使用示例:

CaptchaConfig config = CaptchaConfig.builder()
    .width(200)
    .height(80)
    .length(6)
    .type(CaptchaType.ALPHANUMERIC)
    .expireTime(Duration.ofMinutes(5))
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: No (some fields may be null if not set) - 空值安全: 否(某些字段未设置时可能为空)
Since:
JDK 25, opencode-base-captcha V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • defaults

      public static CaptchaConfig defaults()
      Creates a default configuration. 创建默认配置。
      Returns:
      the default config | 默认配置
    • builder

      public static CaptchaConfig.Builder builder()
      Creates a builder for configuration. 创建配置构建器。
      Returns:
      a new builder | 新构建器
    • toBuilder

      public CaptchaConfig.Builder toBuilder()
      Creates a builder from this configuration. 从此配置创建构建器。
      Returns:
      a builder with current values | 具有当前值的构建器
    • getWidth

      public int getWidth()
      Gets the image width. 获取图像宽度。
      Returns:
      the width in pixels | 宽度(像素)
    • getHeight

      public int getHeight()
      Gets the image height. 获取图像高度。
      Returns:
      the height in pixels | 高度(像素)
    • getLength

      public int getLength()
      Gets the captcha character length. 获取验证码字符长度。
      Returns:
      the number of characters | 字符数
    • getType

      public CaptchaType getType()
      Gets the captcha type. 获取验证码类型。
      Returns:
      the captcha type | 验证码类型
    • getExpireTime

      public Duration getExpireTime()
      Gets the expiration time. 获取过期时间。
      Returns:
      the expire duration | 过期时长
    • getNoiseLines

      public int getNoiseLines()
      Gets the number of noise lines. 获取干扰线数量。
      Returns:
      the noise line count | 干扰线数量
    • getNoiseDots

      public int getNoiseDots()
      Gets the number of noise dots. 获取干扰点数量。
      Returns:
      the noise dot count | 干扰点数量
    • getFontSize

      public float getFontSize()
      Gets the font size. 获取字体大小。
      Returns:
      the font size in points | 字体大小(磅)
    • getFontName

      public String getFontName()
      Gets the font name. 获取字体名称。
      Returns:
      the font name | 字体名称
    • getBackgroundColor

      public Color getBackgroundColor()
      Gets the background color. 获取背景颜色。
      Returns:
      the background color | 背景颜色
    • getFontColors

      public Color[] getFontColors()
      Gets the font color palette. 获取字体颜色数组。
      Returns:
      the font colors | 字体颜色数组
    • getFontColorAt

      public Color getFontColorAt(int index)
      Gets a font color by index without array cloning (internal use). 按索引获取字体颜色,无需数组克隆(内部使用)。
      Parameters:
      index - the index (wraps around) | 索引(循环取值)
      Returns:
      the color | 颜色
    • getFontColorCount

      public int getFontColorCount()
      Gets the number of font colors available. 获取可用字体颜色数量。
      Returns:
      the count | 数量
    • isCaseSensitive

      public boolean isCaseSensitive()
      Returns whether verification is case-sensitive. 返回验证是否区分大小写。
      Returns:
      true if case-sensitive | 是否区分大小写
    • getGifFrameCount

      public int getGifFrameCount()
      Gets the GIF frame count. 获取 GIF 帧数。
      Returns:
      the number of GIF frames | GIF 帧数
    • getGifDelay

      public int getGifDelay()
      Gets the GIF frame delay. 获取 GIF 帧延迟。
      Returns:
      the delay between frames in milliseconds | 帧间延迟(毫秒)
    • getCustomFontPaths

      public List<String> getCustomFontPaths()
      Gets the custom font paths. 获取自定义字体路径列表。
      Returns:
      the custom font paths (unmodifiable) | 自定义字体路径列表(不可修改)
    • isRandomFontPerChar

      public boolean isRandomFontPerChar()
      Returns whether each character uses a random different font. 返回每个字符是否使用随机不同字体。
      Returns:
      true if random font per character is enabled | 是否启用每字符随机字体
    • getCharOverlapRatio

      public float getCharOverlapRatio()
      Gets the character overlap ratio. 获取字符重叠比例。
      Returns:
      the overlap ratio (0.0-0.5) | 重叠比例(0.0-0.5)
    • isSineWarpEnabled

      public boolean isSineWarpEnabled()
      Returns whether sine wave warp is enabled. 返回是否启用正弦波变形。
      Returns:
      true if sine warp is enabled | 是否启用正弦波变形
    • isOutlineShadowEnabled

      public boolean isOutlineShadowEnabled()
      Returns whether character outline shadow is enabled. 返回是否启用字符轮廓阴影。
      Returns:
      true if outline shadow is enabled | 是否启用轮廓阴影
    • isBezierNoiseEnabled

      public boolean isBezierNoiseEnabled()
      Returns whether Bezier curve noise is enabled. 返回是否启用贝塞尔穿字噪声。
      Returns:
      true if Bezier noise is enabled | 是否启用贝塞尔噪声
    • getPowDifficulty

      public int getPowDifficulty()
      Gets the PoW (Proof-of-Work) difficulty. 获取 PoW(工作量证明)难度。
      Returns:
      the number of leading zero bits | 前导零位数
    • getAudioSpeedVariation

      public float getAudioSpeedVariation()
      Gets the audio speed variation range. 获取音频语速变化范围。
      Returns:
      the speed variation (0.0-0.5) | 语速变化范围(0.0-0.5)