zoukankan      html  css  js  c++  java
  • djangosimplecaptcha 验证码干扰线随机点位

    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

  • 相关阅读:
    linux 内核配置
    使用 git 下载linux 源码
    订阅 linux 邮件列表注意的问题
    使用反射创建一维数组和二维数组
    反射API
    反射机制
    集合案例--对ArrayList容器中的内容进行排序
    Collections
    TreeSet
    Set容器
  • 原文地址:https://www.cnblogs.com/wananonline/p/10235471.html
Copyright © 2011-2022 走看看