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.jhlabs.image.SwimFilter;
22  import com.jhlabs.image.PinchFilter;
23  import com.jhlabs.math.ImageFunction2D;
24  import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
25  import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
26  import com.octo.captcha.component.image.color.SingleColorGenerator;
27  import com.octo.captcha.component.image.deformation.ImageDeformation;
28  import com.octo.captcha.component.image.deformation.ImageDeformationByBufferedImageOp;
29  import com.octo.captcha.component.image.fontgenerator.FontGenerator;
30  import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
31  import com.octo.captcha.component.image.textpaster.GlyphsPaster;
32  import com.octo.captcha.component.image.textpaster.TextPaster;
33  import com.octo.captcha.component.image.textpaster.glyphsvisitor.*;
34  import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
35  import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
36  import com.octo.captcha.engine.image.ListImageCaptchaEngine;
37  
38  import java.awt.*;
39  import java.util.ArrayList;
40  
41  /***
42   * <p/>
43   * This is the default captcha engine. It provides a sample gimpy challenge that has no automated solution known. It is
44   * based on the Baffle SPARC Captcha.
45   * <p/>
46   * </p>
47   *
48   * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
49   * @version 1.0
50   */
51  public class HotmailEngine2008 extends ListImageCaptchaEngine {
52  
53      /***
54       * this method should be implemented as folow : <ul> <li>First construct all the factories you want to initialize
55       * the gimpy with</li> <li>then call the this.addFactoriy method for each factory</li> </ul>
56       */
57      protected void buildInitialFactories() {
58  
59          //word generator
60          com.octo.captcha.component.word.wordgenerator.WordGenerator dictionnaryWords =
61                  new RandomWordGenerator("ABCDEGHJKLMNRSTUWXY235689");
62  
63          //wordtoimage components
64          TextPaster randomPaster = new GlyphsPaster(8, 8,
65                  new SingleColorGenerator(new Color(0, 0, 80))
66                  ,new GlyphsVisitors[]{
67                          new OverlapGlyphsUsingShapeVisitor(3),
68                          new TranslateAllToRandomPointVisitor(20,20)
69                  }
70                  );
71          
72  
73          BackgroundGenerator back = new UniColorBackgroundGenerator(
74                  218, 48, new Color(238, 238,238));
75  
76          FontGenerator shearedFont = new RandomFontGenerator(30,
77                  35,
78                  new Font[]{
79                          new Font("Caslon",Font.BOLD, 30)
80                  }
81          ,false);
82  
83  
84  
85  
86          SwimFilter swim= new SwimFilter();
87  
88  
89  
90          swim.setScale(30);
91          swim.setAmount(10);
92          swim.setEdgeAction(ImageFunction2D.CLAMP);
93  
94          SwimFilter swim2= new SwimFilter();
95          swim2.setScale(30);
96          swim2.setAmount(10);
97          swim2.setTime(90);
98          swim2.setEdgeAction(ImageFunction2D.CLAMP);
99  
100         java.util.List<ImageDeformation> def =  new ArrayList<ImageDeformation>();
101 
102         def.add(new ImageDeformationByBufferedImageOp(swim));
103         def.add(new ImageDeformationByBufferedImageOp(swim2)); 
104 
105 
106         com.octo.captcha.component.image.wordtoimage.WordToImage word2image;
107         word2image = new DeformedComposedWordToImage(false,shearedFont, back, randomPaster,
108                 new ArrayList<ImageDeformation>(),
109                 //new ArrayList<ImageDeformation>(),
110                                 def,
111                 new ArrayList<ImageDeformation>()
112         );
113          this.addFactory(
114                 new com.octo.captcha.image.gimpy.GimpyFactory(dictionnaryWords,
115                         word2image, false));
116 
117     }
118 }