-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhi2.py
53 lines (39 loc) · 1.22 KB
/
hi2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import string
import random
import numpy, pylab
from PIL import Image, ImageDraw, ImageFont
#import matplotlib.axes3d as axes3d
from mpl_toolkits.mplot3d import Axes3D
def id_generator(size=4, chars=string.ascii_uppercase + string.digits):
captcha_val = ''.join(random.choice(chars) for _ in range(size))
return captcha_val
def threed_gen():
captcha = id_generator()
sz = (70,30)
img = Image.new('L', sz, 255)
drw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", 20)
drw.text((5,5), captcha, font=font)
img.save('test.png')
X , Y = numpy.meshgrid(range(sz[0]),range(sz[1]))
Z = 1-numpy.asarray(img)/255
fig = pylab.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X, -Y, Z, rstride=1, cstride=1)
ax.set_zlim((0,50))
fig.savefig('test2.png')
def main():
print 'Generating Captcha.'
threed_gen()
print 'Captcha generated successfully.'
if __name__ == "__main__":
main()
'''
import string
import random
def id_generator(size=4, chars=string.ascii_uppercase + string.digits):
print ''.join(random.choice(chars) for _ in range(size))
#if __name__ == "__main__":
# main()
id_generator()
'''