|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.github.cage.Cage
public class Cage
Convenient entry class to control captcha generation. This class is thread safe. Example usage:
Cage cage = new GCage
(); // lets make some "G" template captchas
// use new YCage
() for "Y" template or configure it yourself with
// one of the Cage constructors
.
// ...
String token1 = cage.getTokenGenerator()
.next();
String token2 = cage.getTokenGenerator()
.next();
cage.draw
(token1, someOutputstream1);
cage.draw
(token2, someOutputstream2);
Field Summary | |
---|---|
static Float |
DEFAULT_COMPRESS_RATIO
Default compress ratio for image encoders. |
static String |
DEFAULT_FORMAT
Default image encoding format. |
Constructor Summary | |
---|---|
Cage()
Default constructor. |
|
Cage(Painter painter,
IGenerator<Font> fonts,
IGenerator<Color> foregrounds,
String format,
Float compressRatio,
IGenerator<String> tokenGenerator,
Random rnd)
Constructor. |
Method Summary | |
---|---|
byte[] |
draw(String text)
Generate an image and return it in a byte array. |
void |
draw(String text,
OutputStream ostream)
Generate an image and serialize it to the output. |
BufferedImage |
drawImage(String text)
Generates a captcha image. |
Float |
getCompressRatio()
|
IGenerator<Font> |
getFonts()
|
IGenerator<Color> |
getForegrounds()
|
String |
getFormat()
|
Painter |
getPainter()
|
IGenerator<String> |
getTokenGenerator()
|
protected void |
serialize(BufferedImage img,
OutputStream ostream)
Serializes an image to an OutputStream . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Float DEFAULT_COMPRESS_RATIO
public static final String DEFAULT_FORMAT
Constructor Detail |
---|
public Cage()
Cage(Painter, IGenerator, IGenerator, String, Float, IGenerator, Random)
public Cage(Painter painter, IGenerator<Font> fonts, IGenerator<Color> foregrounds, String format, Float compressRatio, IGenerator<String> tokenGenerator, Random rnd)
painter
- to be used for painting, can be nullfonts
- generator used to generate fonts for texts, defaults to a
random chooser from some predefined set of fonts, can be nullforegrounds
- generator used to generate colors for texts, defaults to a
random "not-bright-so-it-is-readable-on-white" color
generator, can be nullformat
- output format, default "jpeg", can be nullcompressRatio
- a number in [0f, 1f] interval if compression should be used
with the output format. The format must support compression
(like jpeg and png). If null no compression is done.tokenGenerator
- a custom String token generator, can be null. If null is
passed a default is created. It is not used by Cage it is only
stored for convenience. Can be retrieved by
getTokenGenerator()
.rnd
- random generator to be used, can be nullMethod Detail |
---|
public void draw(String text, OutputStream ostream) throws IOException
OutputStream.close()
on the supplied output stream.
text
- to be drawn on the imageostream
- captcha image is serialized to this
IOException
- if IO error occurs.public byte[] draw(String text)
text
- to be drawn on the image
public BufferedImage drawImage(String text)
text
- to be drawn
protected void serialize(BufferedImage img, OutputStream ostream) throws IOException
OutputStream
. This method can call
OutputStream.close()
on the supplied output stream.
img
- to be serializedostream
- to be written to
IOException
- if IO error occurs.public Painter getPainter()
public IGenerator<Font> getFonts()
public IGenerator<Color> getForegrounds()
public String getFormat()
public Float getCompressRatio()
public IGenerator<String> getTokenGenerator()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |