The Windows operating system font files are stored in the following locations:
C:\Windows\Fonts
From PIL import image,imagefilter,imagedraw,imagefontimport random# random Letter Def Rndchar (): return Chr (Random.randint ( 65,90)) #随机颜色1:d EF rndcolor (): return (Random.randint (64,255), Random.randint (64,255), Random.randint (64,255)) # Random color 2:def RndColor2 (): return (Random.randint (32,127), Random.randint (32,127), Random.randint (32,127)) #240 * 60: width = 60*4height = 60image = Image.new (' RGB ', (width,height), (255,255,255)) #创建Font对象: Font = imagefont.truetype (' \ c \ Windows\fonts\arial.ttf ', #创建Draw对象:d raw = Imagedraw.draw (image) #填充每个像素: for x in range (width): A for y in range ( Height): draw.point ((x, y), fill = Rndcolor ()) #输出文字: for T in range (4): Draw.text ((60*t+10,10), Rndchar (), font= Font,fill=rndcolor2 ()) #模糊: image = Image.filter (imagefilter.blur) image.save (' f:/code.jpg ', ' jpeg ')
Python generates a verification code