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
73 lines (68 loc) · 2.12 KB
/
0010.py
File metadata and controls
73 lines (68 loc) · 2.12 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#coding = utf-8
# Make check codes
__author__ = 'Forec'
import random
from PIL import Image, ImageDraw, ImageFont, ImageFilter
num = ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',4))
def random_col():
return (random.randint(50,200),random.randint(50,200),random.randint(50,200))
def make( strs, width = 400, height = 200):
im = Image.new( 'RGB', (width, height ), (255,255,255))
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('verdana.ttf',width//4)
font_width , font_height = font.getsize(strs)
strs_len = len(strs)
x = (width - font_width) // 2
y = (height - font_height ) //2
total_dex = 0
for i in strs:
draw.text((x,y), i, random_col(), font)
temp = random.randint(-30,30)
total_dex += temp
im = im.rotate(temp)
draw = ImageDraw.Draw(im)
x += font_width/strs_len
im = im.rotate(-total_dex)
draw = ImageDraw.Draw(im)
draw.line(
[(random.randint(0,width//4),
random.randint(0,height//4)
),
(random.randint(width//4*3,width),
random.randint(height//4*3,height)
)],
fill = random_col(),
width = width // 80
)
draw.line(
[(random.randint(0,width//4),
random.randint(height//4*3,height)
),
(random.randint(width//3*2,width),
random.randint(0,height//3)
)],
fill = random_col(),
width = width // 80
)
draw.line(
[(random.randint(width//4*3,width),
random.randint(height//4*3,height)
),
(random.randint(width//3*2,width),
random.randint(0,height//3)
)],
fill = random_col(),
width = width // 80
)
# im = im.crop((width//10,height//10,width,height))
for x in range(width):
for y in range(height):
col = im.getpixel((x,y))
if col == (255,255,255) or col == (0,0,0):
draw.point((x,y), fill = random_col())
im = im.filter(ImageFilter.BLUR)
# im.show()
# im = im.convert('L')
im.save('out.jpg')
if __name__ == '__main__':
make(num)