forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomLetter.py
More file actions
38 lines (24 loc) · 857 Bytes
/
RandomLetter.py
File metadata and controls
38 lines (24 loc) · 857 Bytes
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
#!/usr/bin.env python
from random import choice
import string
import Image
import ImageDraw
import ImageFont
import ImageFilter
def generateRandomLetters():
return ''.join([choice(string.ascii_uppercase) for x in range(4)])
def createVerifyImg(str):
img = Image.new('RGB', (240,60), (255,255,255))
font = ImageFont.truetype('DejaVuSansMono.ttf', 36)
draw = ImageDraw.Draw(img)
for x in range(240):
for y in range(60):
draw.point((x,y), tuple([choice(range(128,255)) for color in range(3)]))
for x in range(len(str)):
draw.text((60 * x + 10, 10), str[x], tuple([choice(range(32,127)) for color in range(3)]), font)
img = img.filter(ImageFilter.BLUR)
return img
if __name__ == "__main__":
img = createVerifyImg(generateRandomLetters())
img.show()
img.save("verifyImg.jpg")