如何更改 JCaptcha 生成配置?

发布于 2024-08-21 07:22:04 字数 407 浏览 6 评论 0原文

我已经根据 Jcaptcha 站点的示例建立了 Jcaptcha,但我需要使用颜色和字体配置默认的 jcaptcha。

我设法找到这个 Configuration Jcaptcha with Spring< /a>,但是这是使用 Spring 的情况。我是 Java 新手,不使用 Spring,我可以知道如何为我的 jcaptcha 图像创建新的验证码配置吗?

先感谢您。

I have put up a Jcaptcha based on the example from the Jcaptcha site, but I need to configure the default jcaptcha with colors and fonts.

I managed to find this Configuration Jcaptcha with Spring, however this is with the use of Spring. I am a newbie with Java, and not using Spring, may I know how can I create new captcha configuration for my jcaptcha image?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜中书 2024-08-28 07:22:04

您指向的示例确实是针对 Spring 框架的。但这在这里无关紧要。我可以想象一个不知道依赖注入如何工作的人可能会遇到的困难。所以这里以编程方式来说是同样的事情。请注意,为了简洁起见,我将把它缩短。

  • 您需要从给定的 URL 创建 ImageCaptchaFactory,com.octo.captcha.image.gimpy.GimpyFactory
  • 将其提供给 ImageCaptchaEngine,同时实例化您的验证码引擎,即 com.octo。 captcha.engine.GenericCaptchaEngine
  • 然后将其传递给您的验证码服务,com.octo.captcha.service.multitype.GenericManageableCaptchaService

现在介绍颜色和字体。您需要向验证码工厂提供有关颜色和字体的信息。如何?在这里,

  • 工厂接受两个参数,对象类型、单词生成器和单词到图像合成器,com.octo.captcha.component.wordgenerator.DictionaryWordGeneratorcom.分别为 octo.captcha.component.image.wordtoimage.ComposedWordToImage
  • 单词生成器与颜色和字体无关,因此我们留下单词到图像合成器。因此,您需要在实例化时向 Composer 提供这些,或者可能有一些可用的设置器。查看文档
  • 该示例显示了生成随机字体的配置,如果您不希望它阅读文档。 ,如示例所示,您需要使用您选择的可用字体创建 com.octo.captcha.component.image.fontgenerator.RandomFontGenerator 的实例,并将其传递给工厂
  • 准确地说 同样,您将实例化相关颜色对象,查看 com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator 以获得背景颜色,并查看 com.octo.captcha.component.image。 color.SingleColorGenerator 用于颜色
  • 对于随机颜色,请查看 com.octo.captcha.component.image.color.RandomRangeColorGenerator

The example you are pointing to is, indeed, for Spring Framework. But thats is of little concern here. I can imagine the difficulty one might have, who has no idea about how dependency injection works. So here is the same thing programmatically. Note, I will cut it short for brevity.

  • You need to create ImageCaptchaFactory, from your given URL its, com.octo.captcha.image.gimpy.GimpyFactory
  • Supply that to the ImageCaptchaEngine, while instantiating your captcha engine, namely com.octo.captcha.engine.GenericCaptchaEngine
  • And then pass that to your captcha service, com.octo.captcha.service.multitype.GenericManageableCaptchaService

Now about the colors and fonts. You will need to give information about colors and fonts to your captcha factory. How? Here you go,

  • The factory is taking two arguments, of object type, word generator and word-to-image-composer, com.octo.captcha.component.wordgenerator.DictionaryWordGenerator and com.octo.captcha.component.image.wordtoimage.ComposedWordToImage, respectively
  • Word generator has nothing to do with color and fonts, so we left with the word-to-image composer. So, you need to provide those to composer at the time of instantiation, or perhaps there are some setters available. Check out the docs
  • The example is showing the config to generate random fonts, if you don't want it read the docs. Precisely, whats shown in the example there, you will need to create an instance of com.octo.captcha.component.image.fontgenerator.RandomFontGenerator with your choice of available fonts and pass that to the factory
  • Quite similarly, you will be instantiating relevant color objects, look into com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator for background color, and com.octo.captcha.component.image.color.SingleColorGenerator for color
  • For random colors look at, com.octo.captcha.component.image.color.RandomRangeColorGenerator
南风起 2024-08-28 07:22:04

我们可以根据需要更改 Jcaptcha 图像
检查此页面,然后您可以通过更改颜色生成器、字体生成器、背景生成器和文字生成器来配置验证码

http://instantjavasolutions.blogspot.in/2014/09/how-to-change-jcaptcha-configurations.html

We can change Jcaptcha image as we want
check this page then you can configure your captcha by changing color generators, font generators, background generators and word generators

http://instantjavasolutions.blogspot.in/2014/09/how-to-change-jcaptcha-configurations.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文