Changeset 682
- Timestamp:
- 12/04/06 09:20:10
- Files:
-
- qPloneCaptchas/trunk/config.py (modified) (1 diff)
- qPloneCaptchas/trunk/utils.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
qPloneCaptchas/trunk/config.py
r681 r682 16 16 DEFAULT_BG = 'gray' 17 17 DEFAULT_FONT_COLOR = 'black' 18 DEFAULT_PERIOD = 0.1 018 DEFAULT_PERIOD = 0.1 19 19 DEFAULT_AMPLITUDE = 5 20 20 DEFAULT_OFFSET = (0.5, 0.5) qPloneCaptchas/trunk/utils.py
r681 r682 7 7 from DateTime import DateTime 8 8 import re 9 import math 9 10 try: 10 11 import Crypto.Cipher.DES as Crypto … … 15 16 return md5.new(s).hexdigest().upper() 16 17 18 def getTransform(x, y, a, p, o): 19 return (math.sin( (y+o[0])*p )*a + x, math.sin( (x+o[1])*p )*a + y) 20 17 21 def gen_captcha(**kwargs): 18 22 """Generate a captcha image""" … … 22 26 import ImageDraw 23 27 import ImageFilter 24 import random , math28 import random 25 29 from PIL import ImageFile as pyImageFile 26 30 import sys … … 28 32 from cStringIO import StringIO 29 33 30 if kwargs.has_key('text'): 31 text = kwargs['text'] 32 else: 33 text = None 34 35 if kwargs.has_key('size'): 36 fnt_sz = kwargs['size'] 37 else: 38 fnt_sz = DEFAULT_IMAGE_SIZE 39 40 if kwargs.has_key('bkground'): 41 bkground = kwargs['bkground'] 42 else: 43 bkground = DEFAULT_BG 44 45 if kwargs.has_key('font_color'): 46 font_color = kwargs['font_color'] 47 else: 48 font_color = DEFAULT_FONT_COLOR 49 50 if kwargs.has_key('distortion'): 51 distortion = kwargs['distortion'] 52 else: 53 distortion = DEFAULT_DISTORTION 34 text = kwargs.get('text', None) 35 fnt_sz = kwargs.get('size', DEFAULT_IMAGE_SIZE) 36 bkground = kwargs.get('bkground', DEFAULT_BG) 37 font_color = kwargs.get('font_color', DEFAULT_FONT_COLOR) 38 distortion = kwargs.get('distortion', DEFAULT_DISTORTION) 54 39 55 40 period = distortion[0] 56 41 amplitude = distortion[1] 57 42 offset = distortion[2] 58 59 def getTransform(image):60 return (lambda x, y,61 a = amplitude,62 p = period,63 o = offset:64 (math.sin( (y+o[0])*p )*a + x,65 math.sin( (x+o[1])*p )*a + y))66 43 67 44 outFile = StringIO() … … 87 64 draw.text((x,y), text, font=font, fill=font_color) 88 65 89 #------------------------------render Distortion 3-----------------------66 #------------------------------render Distortion ----------------------- 90 67 r = 1 91 68 xPoints = image.size[0] / r + 2 92 69 yPoints = image.size[1] / r + 2 93 f = getTransform(image)94 70 95 71 # Create a list of arrays with transformed points … … 100 76 yRow = [] 101 77 for i in xrange(xPoints): 102 x, y = f(i*r, j*r)78 x, y = getTransform(i*r, j*r, amplitude, period, offset) 103 79 104 80 # Clamp the edges so we don't get black undefined areas
