import random
from PIL
import Image
, ImageDraw
, ImageFont
width
, height
, font_size
, font_num
= 300, 100, 48, 4
bg_color
= (random
.randint
(0, 255), random
.randint
(0, 255), random
.randint
(0, 255))
image
= Image
.new
(mode
='RGB', size
=(width
, height
), color
=bg_color
)
draw
= ImageDraw
.Draw
(image
, mode
='RGB')
font
= ImageFont
.truetype
("C:\\Windows\\Fonts\\Arial.ttf", font_size
)
verify
= str()
for i
in range(font_num
):
x
= random
.randint
(i
*(width
/font_num
), (i
+1)*(width
/font_num
)-font_size
)
y
= random
.randint
(0, height
-font_size
)
char
= random
.choice
([chr(alpha
) for alpha
in range(65, 117)] + [str(num
) for num
in range(10)])
color
= (random
.randint
(0, 255), random
.randint
(0, 255), random
.randint
(0, 255))
draw
.text
((x
, y
), char
, fill
=color
, font
=font
)
image
.show
()
转载请注明原文地址:https://blackberry.8miu.com/read-11219.html