Apache » Cocoon »

  Cocoon Captcha

Cocoon Captcha 1.0



The CaptchaReader is a simple tool generating JPEG images for the text supplied as its source in a way so that it's hard to parse automatically.

Basic information

Component typeReader
Cocoon blockcaptcha
Java classorg.apache.cocoon.reading.CaptchaReader
Name in Sitemap


The CaptchaReader is a simple reader generating JPEG images for the text supplied as its source in a way so that it's hard to parse automatically.

CAPTCHA means quite literally Completely Automated Public Turing Test to Tell Computers and Humans Apart and one of the best resources on this can be found at the Carnegie Mellon School of Computer Science CAPTCHA project..

This reader creates very simple CAPTCHAs from within a Cocoon pipeline, enabling quick and safe end-user presence identification. As an example, look at the following pipeline snippet:

 <map:match pattern="*">
   <map:read type="captcha" src="{1}"/>

The example will produce an image containing the text in "{1}" "warped" or "bent" in a way similar to the Adobe® Photoshop® "Wave" filter plugin.

Few pipeline parameters control the operation of the CaptchaReader (this component is not configurable):

  • width: the width of the image to generate (default: 100).
  • height: the height of the image to generate (default: 50).
  • foreground: the text foreground color (default: random).
  • background: the image background color (default: white).
  • font: the font to use for the text (default: serif).
  • scale: the scaling factor for interim images (default: 5).
  • amount: the amount of text warping to apply (default: 1).
  • quality: the JPEG encoding quality (default: 0.75).
Note that when the foreground parameter is not specified, the color used to write the text will be randomly chosen in a way that it contrasts well with the background color to avoid problems of illegible text.Both the foreground and background parameters accept strings in the format specified by Color.decode(String) (for example fff, or 0099CC) or one of the field names of the Color class (for example BLACK or cyan ...).The scale parameter controls how much the specified size should be scaled while processing the interim images: the bigger the scaling factor, the better the image quality, but also the memory used while generating the final image will be bigger. In other words, use this with care.The amount parameter is interpreted as a floating point number and must be greater than zero. This controls how much text should be warped, and normally a value of 1 produce quite-good warping. Increasing (or decreasing) this value will produce more (ore less) warping.Remember that in no way the CaptchaReader claims to be able to generate "unbreakable" text (that will be impossible), and improvements to the algorithm are welcome.
Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).