comparison pycaptcha/Captcha/Visual/Tests.py @ 87:4775b4195b4b

code pour la generation de captchas
author goldfinger
date Thu, 11 Feb 2010 05:09:46 -0500
parents
children
comparison
equal deleted inserted replaced
86:b3d76ebf2fac 87:4775b4195b4b
1 """ Captcha.Visual.Tests
2
3 Visual CAPTCHA tests
4 """
5 #
6 # PyCAPTCHA Package
7 # Copyright (C) 2004 Micah Dowty <micah@navi.cx>
8 #
9
10 from Captcha.Visual import Text, Backgrounds, Distortions, ImageCaptcha
11 from Captcha import Words
12 import random
13
14 __all__ = ["PseudoGimpy", "AngryGimpy", "AntiSpam"]
15
16
17 class PseudoGimpy(ImageCaptcha):
18 """A relatively easy CAPTCHA that's somewhat easy on the eyes"""
19 def getLayers(self):
20 word = Words.defaultWordList.pick()
21 self.addSolution(word)
22 return [
23 # random.choice([
24 # Backgrounds.CroppedImage(),
25 # Backgrounds.TiledImage(),
26 # ]),
27 Text.TextLayer(word, borderSize=1),
28 Distortions.SineWarp(),
29 ]
30
31
32 class AngryGimpy(ImageCaptcha):
33 """A harder but less visually pleasing CAPTCHA"""
34 def getLayers(self):
35 word = Words.defaultWordList.pick()
36 self.addSolution(word)
37 return [
38 # suppression du background
39 # Backgrounds.TiledImage(),
40 # Backgrounds.RandomDots(),
41 Text.TextLayer(word, borderSize=1),
42 # Distortions.SineWarp(periodRange = (0.04, 0.07))
43 Distortions.WigglyBlocks(),
44 ]
45
46
47 class AntiSpam(ImageCaptcha):
48 """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
49 fontFactory = Text.FontFactory(20, "vera/VeraBd.ttf")
50 defaultSize = (512,50)
51
52 def getLayers(self, solution="murray@example.com"):
53 self.addSolution(solution)
54
55 textLayer = Text.TextLayer(solution,
56 borderSize = 2,
57 fontFactory = self.fontFactory)
58
59 return [
60 Backgrounds.CroppedImage(),
61 textLayer,
62 Distortions.SineWarp(amplitudeRange = (3, 5)),
63 ]
64
65 ### The End ###