View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   /*
8    * jcaptcha, the open source java framework for captcha definition and integration
9    * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
10   * See the LICENSE.txt file distributed with this package.
11   */
12  
13  /*
14   * jcaptcha, the open source java framework for captcha definition and integration
15   * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
16   * See the LICENSE.txt file distributed with this package.
17   */
18  
19  package com.octo.captcha.engine.image.gimpy;
20  
21  import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
22  import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
23  import com.octo.captcha.component.image.color.RandomListColorGenerator;
24  import com.octo.captcha.component.image.deformation.ImageDeformation;
25  import com.octo.captcha.component.image.deformation.ImageDeformationByBufferedImageOp;
26  import com.octo.captcha.component.image.fontgenerator.FontGenerator;
27  import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
28  import com.octo.captcha.component.image.textpaster.*;
29  import com.octo.captcha.component.image.textpaster.glyphsvisitor.*;
30  import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
31  import com.octo.captcha.engine.image.ListImageCaptchaEngine;
32  import com.jhlabs.image.PinchFilter;
33  import com.jhlabs.math.ImageFunction2D;
34  
35  import java.awt.*;
36  import java.util.*;
37  import java.util.List;
38  
39  /***
40   * <p/>
41   * This is the default captcha engine. It provides a sample gimpy challenge that has no automated solution known. It is
42   * based on the Baffle SPARC Captcha.
43   * <p/>
44   * </p>
45   *
46   * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
47   * @version 1.0
48   */
49  public class GmailEngine extends ListImageCaptchaEngine {
50  
51      /***
52       * this method should be implemented as folow : <ul> <li>First construct all the factories you want to initialize
53       * the gimpy with</li> <li>then call the this.addFactoriy method for each factory</li> </ul>
54       */
55      protected void buildInitialFactories() {
56  
57          //word generator
58          com.octo.captcha.component.word.wordgenerator.WordGenerator dictionnaryWords = //new ConstantWordGenerator("gefefi");
59                  new com.octo.captcha.component.word.wordgenerator.ComposeDictionaryWordGenerator(
60                          new com.octo.captcha.component.word.FileDictionary(
61                                  "toddlist"));
62          //wordtoimage components
63          TextPaster randomPaster = new GlyphsPaster(7, 7,
64                  new RandomListColorGenerator(
65                          new Color[]{
66                                  new Color(23, 170, 27),
67                                  new Color(220, 34, 11),
68                                  new Color(23, 67, 172)})
69                  ,new GlyphsVisitors[]{
70                  new TranslateGlyphsVerticalRandomVisitor(1),
71                 // new RotateGlyphsRandomVisitor(Math.PI/32),
72                  new OverlapGlyphsUsingShapeVisitor(3),
73                  new TranslateAllToRandomPointVisitor()
74                  //,
75  
76                 //
77                  });
78          /*
79           new TextVisitor[]{
80                  new OverlapGlyphsTextVisitor(6)
81          }, null
82           */
83          BackgroundGenerator back = new UniColorBackgroundGenerator(
84                  200, 70, Color.white);
85  
86          FontGenerator shearedFont = new RandomFontGenerator(50,
87                  50,
88                  new Font[]{
89                          new Font("nyala",Font.BOLD, 50)
90                          ,
91                          new Font("Bell MT",  Font.PLAIN, 50)
92                          ,
93                          new Font("Credit valley",  Font.BOLD, 50)
94                  }
95          ,false);
96  
97  
98          PinchFilter pinch = new PinchFilter();
99  
100         pinch.setAmount(-.5f);
101         pinch.setRadius(70);
102         pinch.setAngle((float) (Math.PI/16));
103         pinch.setCentreX(0.5f);
104         pinch.setCentreY(-0.01f);
105         pinch.setEdgeAction(ImageFunction2D.CLAMP);       
106 
107         PinchFilter pinch2 = new PinchFilter();
108         pinch2.setAmount(-.6f);
109         pinch2.setRadius(70);
110         pinch2.setAngle((float) (Math.PI/16));
111         pinch2.setCentreX(0.3f);
112         pinch2.setCentreY(1.01f);
113         pinch2.setEdgeAction(ImageFunction2D.CLAMP);
114 
115         PinchFilter pinch3 = new PinchFilter();
116         pinch3.setAmount(-.6f);
117         pinch3.setRadius(70);
118         pinch3.setAngle((float) (Math.PI/16));
119         pinch3.setCentreX(0.8f);
120         pinch3.setCentreY(-0.01f);
121         pinch3.setEdgeAction(ImageFunction2D.CLAMP);
122 
123 
124 
125         List<ImageDeformation> textDef =  new ArrayList<ImageDeformation>();
126         textDef.add(new ImageDeformationByBufferedImageOp(pinch));
127         textDef.add(new ImageDeformationByBufferedImageOp(pinch2));
128         textDef.add(new ImageDeformationByBufferedImageOp(pinch3));
129 
130         //word2image 1
131         com.octo.captcha.component.image.wordtoimage.WordToImage word2image;
132         word2image = new DeformedComposedWordToImage(false,shearedFont, back, randomPaster,
133                 new ArrayList<ImageDeformation>(),
134                 new ArrayList<ImageDeformation>(),
135                 textDef
136 
137 
138         );
139 
140 
141         this.addFactory(
142                 new com.octo.captcha.image.gimpy.GimpyFactory(dictionnaryWords,
143                         word2image, false));
144 
145     }
146 }