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