//平时学习中写的Python模块代码
1.简易验证码
1 import Image, ImageDraw, ImageFont, ImageFilter 2 import random 3 4 def rndChr(): 5 return chr(random.randint(48, 57)) 6 7 def rndColor(): 8 return (random.randint(64,255), random.randint(64, 255), random.randint(64,255)) 9 10 def rndColor2(): 11 return (random.randint(32, 127), random.randint(32,127), random.randint(32,127)) 12 13 width = 60*4 14 height = 60 15 image = Image.new('RGB', (width, height), (255, 255, 255)) 16 font = ImageFont.truetype('F:\Arial\Arial.ttf', 36) 17 draw = ImageDraw.Draw(image) 18 for x in range(width): 19 for y in range(height): 20 draw.point((x, y), fill = rndColor()) 21 22 for t in range(4): 23 draw.text((60*t+10, 10), rndChr(), font = font, fill=rndColor2()) 24 25 image = image.filter(ImageFilter.BLUR) 26 image.save('F:\Arial\code.jpg', 'jpeg')