forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0010.py
More file actions
29 lines (23 loc) · 943 Bytes
/
Copy path0010.py
File metadata and controls
29 lines (23 loc) · 943 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
#!/usr/bin/env python3
#generate random verification codes in letters
import random, string
from PIL import Image, ImageDraw, ImageFont, ImageFilter
def gene_verification_code_pic():
#initialize
im = Image.new('RGB', (200, 50), (255, 255, 255))
font = ImageFont.truetype('arial.ttf', 30)
draw = ImageDraw.Draw(im)
#init background with light color
for i in range(200):
for j in range(50):
draw.point((i, j), fill=(random.randint(128,255),random.randint(128,255),random.randint(128,255)))
#init letters with deep color
for t in range(4):
draw.text((50*t+10, 10), random.choice(string.ascii_letters), font=font, fill=(random.randint(0,127), random.randint(0,127), random.randint(0,127)))
#make the pic blurred
im = im.filter(ImageFilter.BLUR)
return im
if __name__ == '__main__':
im = gene_verification_code_pic()
im.show()
im.save('res.jpg')