jl.
jl.

Reputation: 2239

How to Change the JCaptcha generation configuration?

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.

Upvotes: 3

Views: 6255

Answers (2)

Adeel Ansari
Adeel Ansari

Reputation: 39907

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

Upvotes: 4

Sanju2014
Sanju2014

Reputation: 46

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

Upvotes: 1

Related Questions