Skip to main content

一个图形验证码生成工具

Project description

Kaptcha:python 验证码生成工具

Kaptcha

简述

优点

  • 调用简单
  • 高度自定义
  • 生成快速

示例

类型(干扰都为5) 内容 图片
字母数字混合型 7w8W HyGU
数字型 5244 5244
字母型 Ehqx jFbF
增强型 wd81 wd81
边缘凸显 bpCk bpCk
浮雕效果 MkT6 MkT6
轮廓 qXLT qXLT
GIF动态图 VbFe VbFe

生成速度

类型 1000次生成平均单次速度
基本样式(Base64) 1.48ms
基本样式(PIL.Image) 1.32ms
滤镜渲染(Base64) 1.57ms
GIF动图 10.93ms

如何使用

简单的使用

import kaptcha

x, y = kaptcha.Captcha().letter_digit()
# x 是生成的文字
# y 是生成的 base64 图像
print(x, y)
  1. 数英混合

    import kaptcha
    
    x, y = kaptcha.Captcha().letter_digit()
    print(x, y)
    
  2. 纯英文

    import kaptcha
    
    x, y = kaptcha.Captcha().letter()
    print(x, y)
    
  3. 纯数字

    import kaptcha
    
    x, y = kaptcha.Captcha().digit()
    print(x, y)
    #4696 data:image/jpeg;base64,/9j/4AAQSkZJR……
    

详细使用方法

kaptcha.Captcha(width=200,  # 验证码的宽度 px
                 height=80,  # 验证码的高度 px
                 chips=5,  # 干扰点 强度(1-20)
                 mode="RGB",  # 色彩模式 RGB\L
                 imageObj=False,  # 返回 PIL.Image 格式
                 gif=False,  # gif 格式验证码(不可与imageObj同为真)
                 font: list = None,  # 字体路径列表
                 bg="white",  # 背景颜色 颜色代码或 16 进制
                 contour=False,  # 以下四个滤镜只可开启一个
                 enhance=False,
                 edge=False,
                 emboss=False
                 )

# length调整字符串长度(建议同时调整width)
Captcha().letter(length=4)  # 英文
Captcha().digit(length=4)  # 数字
Captcha().letter_digit(length=4)  # 数英
Captcha(gif=True).letter_digit(length=4)  # 动态图
 
# 绘制函数
kaptcha.CaptchaPainter(text="",  # 绘制文字
                       im_x=260,  # 验证码的宽度 px
                       im_y=125,   # 验证码的高度 px
                       gran=5,  # 干扰点 强度(1-20)
                       mode="RGB",  # 色彩模式 RGB\L
                       font: list = None,  # 字体路径列表
                       bg="white"  # 背景颜色 颜色代码或 16 进制
                      )
CaptchaPainter().normal  # 静态图(-> PIL.Image)
CaptchaPainter().gif()  # 动态图(-> BytesIO())
返回值
# 当imageObj=False(默认) -> 返回 (str, base64: str)
Captcha().letter(length=4)
print(Captcha().letter(length=4)[1])  # > data:image/jpeg;base64,/9j/4AAQSkZJR......


# 当imageObj=True -> 返回 (str, PIL.Image)
Captcha(imageObj=True).letter(length=4)
Captcha(imageObj=True).letter(length=4)[1].show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaptcha-1.0.0.tar.gz (498.8 kB view details)

Uploaded Source

Built Distribution

kaptcha-1.0.0-py3-none-any.whl (362.4 kB view details)

Uploaded Python 3

File details

Details for the file kaptcha-1.0.0.tar.gz.

File metadata

  • Download URL: kaptcha-1.0.0.tar.gz
  • Upload date:
  • Size: 498.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for kaptcha-1.0.0.tar.gz
Algorithm Hash digest
SHA256 191ebbcb20c4c1d42c28838e3b7f62df4ea2a31a1d95d0f083d16d37723c4bc1
MD5 83f902cdadb958f6a916be86613636b8
BLAKE2b-256 815bc01eb6880f321b4a3145d0a56efc3657438cfafe28428a615a792d8163a9

See more details on using hashes here.

File details

Details for the file kaptcha-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kaptcha-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 362.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for kaptcha-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dc192223cd343f1168142356e89b21f2f0907a0b7ae55f9a0cd8dc184fd0240
MD5 20f8ef3f31c619c5996442901db01f2b
BLAKE2b-256 8e15ffda7ea78b5c6d037a593f074ecb6eca061e12a919145d075de18573e815

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page