|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avalon.framework.logger.AbstractLogEnabled org.apache.cocoon.reading.AbstractReader org.apache.cocoon.reading.CaptchaReader
public class CaptchaReader
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.
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 identificat. As an example, look at the following pipeline snippet:
<map:match pattern="*"> <map:read type="captcha" src="{1}"/> </map:match>
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 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.
Field Summary |
---|
Fields inherited from class org.apache.cocoon.reading.AbstractReader |
---|
objectModel, out, parameters, resolver, source |
Fields inherited from interface org.apache.cocoon.reading.Reader |
---|
ROLE |
Constructor Summary | |
---|---|
CaptchaReader()
|
Method Summary | |
---|---|
void |
generate()
Create an image containing the text specified as this reader source warped to avoid automatic interpretation. |
String |
getMimeType()
The content type of the generated content: image/jpeg . |
Methods inherited from class org.apache.cocoon.reading.AbstractReader |
---|
getLastModified, recycle, setOutputStream, setup, shouldSetContentLength |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
---|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CaptchaReader()
Method Detail |
---|
public String getMimeType()
The content type of the generated content: image/jpeg
.
getMimeType
in interface SitemapOutputComponent
getMimeType
in class AbstractReader
image/jpeg
.AbstractProcessingPipeline.setMimeTypeForSerializer(org.apache.cocoon.environment.Environment)
,
AbstractProcessingPipeline.setMimeTypeForReader(org.apache.cocoon.environment.Environment)
public void generate() throws IOException
Create an image containing the text specified as this reader source warped to avoid automatic interpretation.
IOException
- if an I/O error occurred generating the image.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |