-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerificationCode.py
More file actions
38 lines (29 loc) · 893 Bytes
/
Copy pathVerificationCode.py
File metadata and controls
38 lines (29 loc) · 893 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
from PIL import Image, ImageFilter, ImageFont, ImageDraw
import random
# 随机字母
def rndChar():
return chr(random.randint(65, 90))
# 随机颜色
def rndColor():
return (random.randint(66, 127), random.randint(66, 127),
random.randint(66, 127))
def rndColor2():
return (random.randint(129, 255), random.randint(129, 255),
random.randint(129, 255))
font = ImageFont.truetype('arial.ttf', 36)
width = 240
height = 60
# 创建画板
image = Image.new("RGB", (width, height), (255, 255, 255))
# 以image为画板
draw = ImageDraw.Draw(image)
# 填充每一个像素
for x in range(width):
for y in range(height):
draw.point((x, y), fill=rndColor())
# 填充字母
for x in range(4):
draw.text((60 * x + 10, 10), rndChar(), fill=rndColor2(), font=font)
# 模糊
image = image.filter(ImageFilter.BLUR)
image.save("code.jpg", "jpeg")