source: products/qPloneCaptchas/tags/1.3.0/skins/plone_captchas/dynamic/getCaptchaImage.py

Last change on this file was 1, checked in by myroslav, 19 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1## Script (Python) "getCaptchaImage"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9from Products.qPloneCaptchas.utils import gen_captcha, decrypt, \
10     getWord, parseKey
11from Products.CMFCore.utils import getToolByName
12import random
13propTool = getToolByName(context, 'portal_properties')
14captchaProps = propTool['qPloneCaptchas']
15
16hk = context.REQUEST.traverse_subpath[0]
17dk = decrypt(context.captcha_key, hk)
18key = parseKey(dk)['key']
19
20text = getWord(int(key))
21size = captchaProps.getProperty('image_size')
22bkground = captchaProps.getProperty('background')
23font_color = captchaProps.getProperty('font_color')
24kwargs = {'text': text,
25          'size': size,
26          'bkground': bkground,
27          'font_color': font_color}
28if captchaProps.getProperty('random_params', 'False'):
29    period = random.uniform(0.05, 0.12)
30    amplitude = random.uniform(3.0, 6.5)
31else:
32    period = captchaProps.getProperty('period')
33    amplitude = captchaProps.getProperty('amplitude')
34
35kwargs['distortion'] = [period, amplitude, (0.0, 0.0)]
36
37im = gen_captcha(**kwargs)
38context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpeg')
39context.REQUEST.RESPONSE.setHeader('Content-Length', im['size'])
40context.REQUEST.RESPONSE.setHeader('Accept-Ranges', 'bytes')
41return im['src']
Note: See TracBrowser for help on using the repository browser.