Module bus.extra

Class GifProvider

java.lang.Object
org.miaixz.bus.extra.captcha.AbstractProvider
org.miaixz.bus.extra.captcha.provider.GifProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Provider, CaptchaProvider

public class GifProvider extends AbstractProvider
Gif CAPTCHA Provider.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • GifProvider

      public GifProvider(int width, int height)
      Constructor to set CAPTCHA width and height.
      Parameters:
      width - CAPTCHA width.
      height - CAPTCHA height.
    • GifProvider

      public GifProvider(int width, int height, int codeCount)
      Constructor.
      Parameters:
      width - CAPTCHA width.
      height - CAPTCHA height.
      codeCount - Number of characters.
    • GifProvider

      public GifProvider(int width, int height, int codeCount, int interfereCount)
      Constructor.
      Parameters:
      width - CAPTCHA width.
      height - CAPTCHA height.
      codeCount - Number of characters.
      interfereCount - Number of interfering elements.
    • GifProvider

      public GifProvider(int width, int height, CodeStrategy generator, int interfereCount)
      Constructor.
      Parameters:
      width - Image width.
      height - Image height.
      generator - CAPTCHA code generator.
      interfereCount - Number of interfering elements.
    • GifProvider

      public GifProvider(int width, int height, int codeCount, int interfereCount, float sizeBaseHeight)
      Constructor.
      Parameters:
      width - Image width.
      height - Image height.
      codeCount - Number of characters.
      interfereCount - Number of interfering elements.
      sizeBaseHeight - Font size as a multiplier of the height.
  • Method Details

    • setQuality

      public GifProvider setQuality(int quality)
      Sets the image's color quantization (conversion quality to the maximum 256 colors allowed by the GIF specification). Lower values (minimum = 1) produce better colors but are significantly slower to process. 10 is the default and produces good colors at a reasonable speed. Values greater than 20 do not produce significant improvements in speed.
      Parameters:
      quality - greater than 1.
      Returns:
      this
    • setRepeat

      public GifProvider setRepeat(int repeat)
      Sets the number of times the GIF frames should be played. The default is 0, which means an infinite loop. Must be called before the first image is added.
      Parameters:
      repeat - must be greater than or equal to 0.
      Returns:
      this
    • setMaxColor

      public GifProvider setMaxColor(int maxColor)
      Sets the maximum color range.
      Parameters:
      maxColor - the color.
      Returns:
      this
    • setMinColor

      public GifProvider setMinColor(int minColor)
      Sets the minimum color range.
      Parameters:
      minColor - the color.
      Returns:
      this
    • create

      public void create()
      Description copied from interface: CaptchaProvider
      Creates a CAPTCHA. Implementations should generate both a random CAPTCHA string and a CAPTCHA image.
      Specified by:
      create in interface CaptchaProvider
      Overrides:
      create in class AbstractProvider
    • createImage

      protected Image createImage(String code)
      Description copied from class: AbstractProvider
      Creates the CAPTCHA image based on the generated code.
      Specified by:
      createImage in class AbstractProvider
      Parameters:
      code - The CAPTCHA code.
      Returns:
      The CAPTCHA image.