/tags/1.0.0-GA/beangle-blueprint/org.beangle.blueprint.captcha/src/main/java/org/beangle/blueprint/captcha/internal/service/GmailEngine.java

http://beangle.googlecode.com/ · Java · 64 lines · 47 code · 9 blank · 8 comment · 0 complexity · 78c616d98dc984b37b15fc0b1de9da8d MD5 · raw file

  1. package org.beangle.blueprint.captcha.internal.service;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.image.ImageFilter;
  5. import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
  6. import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
  7. import com.octo.captcha.component.image.color.RandomListColorGenerator;
  8. import com.octo.captcha.component.image.deformation.ImageDeformation;
  9. import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
  10. import com.octo.captcha.component.image.fontgenerator.FontGenerator;
  11. import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
  12. import com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster;
  13. import com.octo.captcha.component.image.textpaster.TextPaster;
  14. import com.octo.captcha.component.image.textpaster.textdecorator.TextDecorator;
  15. import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
  16. import com.octo.captcha.component.image.wordtoimage.WordToImage;
  17. import com.octo.captcha.component.word.FileDictionary;
  18. import com.octo.captcha.component.word.wordgenerator.ComposeDictionaryWordGenerator;
  19. import com.octo.captcha.component.word.wordgenerator.WordGenerator;
  20. import com.octo.captcha.engine.image.ListImageCaptchaEngine;
  21. import com.octo.captcha.image.gimpy.GimpyFactory;
  22. /**
  23. * captcha like GMAIL
  24. *
  25. * @author chaostone
  26. *
  27. */
  28. public class GmailEngine extends ListImageCaptchaEngine {
  29. protected void buildInitialFactories() {
  30. Integer minWordLength = new Integer(4);
  31. Integer maxWordLength = new Integer(5);
  32. Integer imageWidth = new Integer(90);
  33. Integer imageHeight = new Integer(35);
  34. int fontSize = 21;
  35. // word generator
  36. WordGenerator dictionnaryWords = new ComposeDictionaryWordGenerator(new FileDictionary(
  37. "toddlist"));
  38. // word2image components
  39. TextPaster randomPaster = new DecoratedRandomTextPaster(minWordLength, maxWordLength,
  40. new RandomListColorGenerator(new Color[] { new Color(23, 170, 27),
  41. new Color(220, 34, 11), new Color(23, 67, 172) }), new TextDecorator[] {});
  42. BackgroundGenerator background = new UniColorBackgroundGenerator(imageWidth, imageHeight,
  43. Color.white);
  44. FontGenerator font = new RandomFontGenerator(new Integer(fontSize), new Integer(fontSize),
  45. new Font[] { new Font("nyala", Font.BOLD, fontSize),
  46. new Font("Bell MT", Font.PLAIN, fontSize),
  47. new Font("Credit valley", Font.BOLD, fontSize) });
  48. ImageDeformation postDef = new ImageDeformationByFilters(new ImageFilter[] {});
  49. ImageDeformation backDef = new ImageDeformationByFilters(new ImageFilter[] {});
  50. ImageDeformation textDef = new ImageDeformationByFilters(new ImageFilter[] {});
  51. WordToImage word2image = new DeformedComposedWordToImage(font, background, randomPaster,
  52. backDef, textDef, postDef);
  53. addFactory(new GimpyFactory(dictionnaryWords, word2image));
  54. }
  55. }