导入的包
import numpy as np
import random as ran
from PIL import Image,ImageDraw,ImageFont,ImageFilter
import time
随机颜色
def rndColor2():
return (ran.randint(32, 127), ran.randint(32, 127), ran.randint(32, 127))
def rndColor():
return (ran.randint(64, 255), ran.randint(64, 255), ran.randint(64, 255))
生成数字和字母,默认为六位
返回一个列表,按时间生产一个图片
#默认6个数字加字母
def seccode(index=6):
#创建随机数
index=int(index)
lett=[chr(i) for i in np.random.randint(65, 90,index)]+[str(i) for i in np.random.randint(0, 9, index)]
#随机切index数
getColor=ran.sample(lett,index)
# *n代表生成几个随机字,与下面生成字符的n对应,,
#width的像素也可以固定长度为240像素
width = 60 * 4
height = 60
# 生成图片
image = Image.new('RGB', (width, height), (255, 255, 255))
# 创建Font对象字体:
font = ImageFont.tru