captcha.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:flask-maple 作者: honmaple 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号