Accueil > > > CAPTCHA EN 3D ISOMETRIQUE
CAPTCHA EN 3D ISOMETRIQUE
Information sur la source
Description
c'est un portage de ce captcha : exlplications et demo (de la version php) ici : http://eelte.megami.fr/ http://www.phpcs.com/codes /CAPTCHA-3D-ISO-LECTURE-FONT-CONSOLE_45049.aspx c ette source n'est pas de moi, elle est de Pierre Bourdon (alias delroth), il a fait une simple traduction de mon code, de php vers python.
Source
- #!/usr/bin/env python
- #-*- encoding: utf-8 -*-
- #
- # captcha.py
- # Library to simply use captchas.
- #
- # Copyright (c) 2008 Pierre "delroth" Bourdon <root@delroth.is-a-geek.org>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- # Original PHP code from coucou747 ( http://eelte.megami.fr ), translated into Python.
-
- import math
- import random
- import sys
- import cgitb
- from PIL import Image, ImageDraw
-
- cgitb.enable()
-
- class Captcha(object):
- """
- A captcha object is used to encapsulate a text and render the image
- with this text, which will generally be randomized.
- """
-
- def randomString(self):
- """
- Returns a random string to use in the captcha, with the most readable
- characters.
- """
- out = ''
- for i in xrange(self.len):
- out += random.choice(self.charset)
- return out
-
- def getMatrix(self):
- """
- Returns the deformation matrix.
- """
- lim_x = 16 * (len(self.text) + 1)
- array = []
- """
- on place les vagues sur la matrice
- """
- for k in xrange(20):
- array.append([])
- for i in xrange(lim_x):
- array[k].append(math.cos((i * self.cy + k * self.cx * math.pi)
- * self.cangle + self.phy) *
- math.sin((i * self.cy + k * self.cx * math.pi)
- * self.cangle + self.phy) * self.h2 * 7)
- """
- update function
- """
- def e(x, y): array[x][y] -= 2 * self.h
- """
- mise a jours de la matrice, pour afficher le texte
- """
- for k in xrange(1, len(self.text) + 1):
- for i in xrange(8):
- for j in xrange(7, -1, -1):
- if ord(self.alphabet[i + 4 + ord(self.text[k - 1]) * 8]) & (1 << j):
- e(i * 2 + 2, k * 16 + 9 - j * 2)
- e(i * 2 + 3, k * 16 + 9 - j * 2)
- e(i * 2 + 2, k * 16 + 10 - j * 2)
- e(i * 2 + 3, k * 16 + 10 - j * 2)
-
- return array
-
- def getColor(self, matrix, color):
- return color * (10 - matrix / 3) / 10
-
- def drawMatrix(self, matrix, image):
- """
- Draws the matrix on the image.
- """
- drawer = ImageDraw.Draw(image)
- s, c = math.sin(self.angle), math.cos(self.angle)
- lx, ly = len(matrix[0]) - 1, len(matrix) - 1
- dx, dy, by = self.dx, self.dy, self.by
- a = matrix
-
- for y in xrange(ly):
- for x in xrange(lx):
- drawer.polygon([((x + y * c) * dx, by + a[y][x] + (y + x * s) * dy),
- ((x + (1 + y) * c) * dx, by + a[y + 1][x] + (y + 1 + x * s) * dy),
- ((x + 1 + (y + 1) * c) * dx, by + a[y + 1][x + 1] + (y + 1 + (x + 1) * s) * dy),
- (((x + 1) + y * c) * dx, by + a[y][x + 1] + (y + (x + 1) * s) * dy)],
- outline=self.color, fill=self.background)
- del drawer
-
- def getImage(self):
- sizex = self.width
- sizey = self.height
- img = Image.new("RGBA", (sizex, sizey), self.background)
- self.drawMatrix(self.matrix, img)
- return img
-
- def loadAlphabet(self):
- return file(self.alphaf).read()
- """
- ces variables devraient etres aleatoires
- """
- def __init__(self, alphaf, charset="bcdefghijklmnopqrstuvwxyz", len=5, width=450, height=160, color=(0, 0, 0, 255), background=(255, 255, 255, 0), angle=-5*3.1415/200, dx=4, dy=6, by=40, h=8, h2=2, cangle=0.055, cx=1.5, cy=1, phy=2):
- l = locals()
- for k in l:
- if k == 'self': continue
- setattr(self, k, l[k])
- self.alphabet = self.loadAlphabet()
- self.text = self.randomString()
- self.matrix = self.getMatrix()
-
- print 'Content-Type: image/png'
- print
-
- if __name__ == '__main__':
- c = Captcha('alt-8x8.psf', color=(0, 0, 255, 255), background=(255, 255, 255, 255))
- c.getImage().save(sys.stdout, 'png')
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
#
# captcha.py
# Library to simply use captchas.
#
# Copyright (c) 2008 Pierre "delroth" Bourdon <root@delroth.is-a-geek.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Original PHP code from coucou747 ( http://eelte.megami.fr ), translated into Python.
import math
import random
import sys
import cgitb
from PIL import Image, ImageDraw
cgitb.enable()
class Captcha(object):
"""
A captcha object is used to encapsulate a text and render the image
with this text, which will generally be randomized.
"""
def randomString(self):
"""
Returns a random string to use in the captcha, with the most readable
characters.
"""
out = ''
for i in xrange(self.len):
out += random.choice(self.charset)
return out
def getMatrix(self):
"""
Returns the deformation matrix.
"""
lim_x = 16 * (len(self.text) + 1)
array = []
"""
on place les vagues sur la matrice
"""
for k in xrange(20):
array.append([])
for i in xrange(lim_x):
array[k].append(math.cos((i * self.cy + k * self.cx * math.pi)
* self.cangle + self.phy) *
math.sin((i * self.cy + k * self.cx * math.pi)
* self.cangle + self.phy) * self.h2 * 7)
"""
update function
"""
def e(x, y): array[x][y] -= 2 * self.h
"""
mise a jours de la matrice, pour afficher le texte
"""
for k in xrange(1, len(self.text) + 1):
for i in xrange(8):
for j in xrange(7, -1, -1):
if ord(self.alphabet[i + 4 + ord(self.text[k - 1]) * 8]) & (1 << j):
e(i * 2 + 2, k * 16 + 9 - j * 2)
e(i * 2 + 3, k * 16 + 9 - j * 2)
e(i * 2 + 2, k * 16 + 10 - j * 2)
e(i * 2 + 3, k * 16 + 10 - j * 2)
return array
def getColor(self, matrix, color):
return color * (10 - matrix / 3) / 10
def drawMatrix(self, matrix, image):
"""
Draws the matrix on the image.
"""
drawer = ImageDraw.Draw(image)
s, c = math.sin(self.angle), math.cos(self.angle)
lx, ly = len(matrix[0]) - 1, len(matrix) - 1
dx, dy, by = self.dx, self.dy, self.by
a = matrix
for y in xrange(ly):
for x in xrange(lx):
drawer.polygon([((x + y * c) * dx, by + a[y][x] + (y + x * s) * dy),
((x + (1 + y) * c) * dx, by + a[y + 1][x] + (y + 1 + x * s) * dy),
((x + 1 + (y + 1) * c) * dx, by + a[y + 1][x + 1] + (y + 1 + (x + 1) * s) * dy),
(((x + 1) + y * c) * dx, by + a[y][x + 1] + (y + (x + 1) * s) * dy)],
outline=self.color, fill=self.background)
del drawer
def getImage(self):
sizex = self.width
sizey = self.height
img = Image.new("RGBA", (sizex, sizey), self.background)
self.drawMatrix(self.matrix, img)
return img
def loadAlphabet(self):
return file(self.alphaf).read()
"""
ces variables devraient etres aleatoires
"""
def __init__(self, alphaf, charset="bcdefghijklmnopqrstuvwxyz", len=5, width=450, height=160, color=(0, 0, 0, 255), background=(255, 255, 255, 0), angle=-5*3.1415/200, dx=4, dy=6, by=40, h=8, h2=2, cangle=0.055, cx=1.5, cy=1, phy=2):
l = locals()
for k in l:
if k == 'self': continue
setattr(self, k, l[k])
self.alphabet = self.loadAlphabet()
self.text = self.randomString()
self.matrix = self.getMatrix()
print 'Content-Type: image/png'
print
if __name__ == '__main__':
c = Captcha('alt-8x8.psf', color=(0, 0, 255, 255), background=(255, 255, 255, 255))
c.getImage().save(sys.stdout, 'png')
Conclusion
ce code se lance comme un cgi sur une page web.
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
charger une image 3D [ par ghadroud ]
Bonjour,Je suis sensée développer une application en python qui charge un image 3D et qui soit inclue dans la page web.Comment procéder a ca?merci
Test sur le "format" d'une chaine de caractères [ par arkwonn ]
Bonjour. Souhaitant personnaliser un script python, ce que je voudrais coder est un "test de format d'une chaine de caractères". Concrètement, je sou
CHERCHE FORMATEUR PYTHON orienté 3D (XSI) [ par potoche ]
Bonjour, Je cherche un spécialiste python appliqué aux logiciels 3D style XSI. Il s'agit d'aider les gros studio à développer leurs outils à l'aide d
[clos] un morpion 3D ( Débutant) [ par heeeeeeeelp ]
Bonsoir ; [size=300][u][b]Alerte[/b][/u] [/size]a tous les geek et/ou fanatique d'informatique & de programmation ,, j'ai besoin de votre génie . Je s
Morpion 3D [ par lola413 ]
Bonjour, Dans le cadre de mon cours de programmation j'ai pour exercice (a rendre pour le 23, youpi!) de réaliser un morpion 4*4 en 3D (alignement de
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
PYVISA PROBLèMEPYVISA PROBLèME par sandrine44
Cliquez pour lire la suite par sandrine44
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|