def create_validate_code(self,
size=(120, 30),
chars=init_chars,
img_type="GIF",
mode="RGB",
bg_color=(255, 255, 255),
fg_color=(0, 0, 255),
font_size=18,
font_type=fontType,
length=4,
draw_lines=True,
n_line=(1, 2),
draw_points=True,
point_chance=2):
width, height = size
img = Image.new(mode, size, bg_color)
draw = ImageDraw.Draw(img)
if draw_lines:
self.create_lines(draw, n_line, width, height)
if draw_points:
self.create_points(draw, point_chance, width, height)
strs = self.create_strs(draw, chars, length, font_type, font_size,
width, height, fg_color)
params = [1 - float(randint(1, 2)) / 100, 0, 0, 0,
1 - float(randint(1, 10)) / 100, float(randint(1, 2)) / 500,
0.001, float(randint(1, 2)) / 500]
img = img.transform(size, Image.PERSPECTIVE, params)
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
return img, strs
评论列表
文章目录