当前位置: 移动技术网 > IT编程>脚本编程>Python > django-simple-captcha 验证码干扰线随机点位

django-simple-captcha 验证码干扰线随机点位

2019年01月08日  | 移动技术网IT编程  | 我要评论

中国红薯网,冲田杏梨作品一览,不是你的错歌词

captcha_noise_functions = ( 'captcha.helpers.noise_null',# 设置样式
                            'captcha.helpers.noise_arcs',# 设置干扰线
                           #'captcha.helpers.noise_arcs_random',  # 设置自定义的干扰线
                           #'captcha.helpers.noise_dots',# 设置干扰点
                        )

官方写的方法干扰线是固定的

captcha_noise_functions = ( 'captcha.helpers.noise_null',# 设置样式
                           # 'captcha.helpers.noise_arcs',# 设置干扰线
                           'captcha.helpers.noise_arcs_random',  # 设置自定义的干扰线
                           #'captcha.helpers.noise_dots',# 设置干扰点
                        )

然后找到captcha/helpers.py  在这个文件添加下面的函数

def noise_arcs_random(draw, image):
    size = image.size
    draw.arc([-20, -20, random.randint(size[0]/1.5, size[0]), random.randint(15, 25)], 0, 295, fill=settings.captcha_foreground_color)
    draw.line([-20, random.randint(5, size[1]), random.randint(size[0]/1.5, size[0]), random.randint(5, size[1])], fill=settings.captcha_foreground_color)
    draw.line([-20, random.randint(5, size[1]), random.randint(size[0]/1.5, size[0]), random.randint(5, size[1])], fill=settings.captcha_foreground_color)
    return draw

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网