view data_generation/transformations/pycaptcha/Facade.py @ 174:ff26436d42d6

Make data_generation.transformations importable and fixup test.py to not try some of the modules.
author Arnaud Bergeron <abergeron@gmail.com>
date Sat, 27 Feb 2010 12:18:26 -0500
parents 1f5937e9e530
children
line wrap: on
line source

#!/usr/bin/env python
import sys, os
curdir = os.path.dirname(__file__)
if curdir != '':
    sys.path.append(curdir)

from Captcha.Visual.Tests import PseudoGimpy, AngryGimpy
import numpy

# Une fonction simple pour generer un captcha
# ease : represente la difficulte du captcha a generer 
#      0 = facile et 1 (ou autre chose) = difficile 
#solution : specifie si on veut en retour un array numpy representant 
#l image ou un tuple contenant l'array et la solution du captcha.

# Des fontes additionnelles peuvent etre ajoutees au dossier pyCaptcha/Captcha/data/fonts/others
# Le programme choisit une fonte aleatoirement dans ce dossier ainsi que le dossir vera.


def generateCaptcha (ease=0, solution=0):

    if ease == 1:
        g = AngryGimpy()

    else:
        g = PseudoGimpy()
    
    i = g.render()
    a = numpy.asarray(i)

    if solution == 0:
       return a

    else :
        return (a, g.solutions)