from
PIL
import
Image, ImageDraw, ImageFont, ImageFilter
import
random
def
rdChr():
return
chr
(random.randint(
65
,
90
))
def
rdColor1():
return
(random.randint(
64
,
255
),random.randint(
64
,
255
),random.randint(
64
,
255
))
def
rdColor2():
return
(random.randint(
32
,
127
),random.randint(
32
,
127
),random.randint(
32
,
127
))
width
=
60
*
4
height
=
80
image1
=
Image.new(
'RGB'
,(width,height),(
255
,
255
,
255
))
font
=
ImageFont.truetype(
'C:\Windows\Fonts\Arial.ttf'
,
50
)
draw
=
ImageDraw.Draw(image1)
for
x
in
range
(width):
for
y
in
range
(height):
draw.point((x, y), fill
=
rdColor1())
for
t
in
range
(
4
):
draw.text((
60
*
t
+
10
,
10
), rdChr(), font
=
font, fill
=
rdColor2())
image1.
filter
(ImageFilter.BLUR)
image1.save(
'字母验证码.jpg'
,
'jpeg'
)