Skip to content

Commit 2ee454c

Browse files
committed
Create 0010.py
1 parent 89c4a25 commit 2ee454c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Liez-python-code/0010/0010.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# codeing: utf-8
2+
3+
from PIL import Image, ImageDraw, ImageFont, ImageFilter
4+
import string
5+
import random
6+
7+
8+
def get4char():
9+
return [random.choice(string.ascii_letters) for _ in range(4)] # 可以把‘_’换做任意字母,‘_’说明后续不用
10+
11+
12+
def getcolor():
13+
return random.randint(30, 100), random.randint(30, 100), random.randint(30, 100)
14+
15+
16+
def getpicture():
17+
width = 240
18+
height = 60
19+
20+
image = Image.new('RGB', (width, height), (180, 180, 180))
21+
font = ImageFont.truetype('arial.ttf', 40)
22+
23+
draw = ImageDraw.Draw(image)
24+
code = get4char()
25+
for ch in range(4):
26+
draw.text((60 * ch,30), code[ch], font=font, fill=getcolor())
27+
28+
for _ in range(random.randint(1500, 3000)):
29+
draw.point((random.randint(0, width), random.randint(0, height)), fill=getcolor())
30+
31+
image = image.filter(ImageFilter.BLUR)
32+
image.save("".join(code) + '.jpg')
33+
34+
35+
getpicture()

0 commit comments

Comments
 (0)