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

如何使用

安装

pip install kaptcha

简单的使用

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()

LICENSE

MIT License

Copyright (c) 2022 AntonVanke


PyPI - DownloadsPyPI - LicenseGitHub Repo stars

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.1.tar.gz (296.8 kB view details)

Uploaded Source

Built Distribution

kaptcha-1.0.1-py3-none-any.whl (296.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kaptcha-1.0.1.tar.gz
  • Upload date:
  • Size: 296.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.1.tar.gz
Algorithm Hash digest
SHA256 d603b66872c77a6cc9d7542844b7e6c10877bad7cc33a3db9eb0ab362c77401d
MD5 f5830057a0519914c9fb16f88fa09497
BLAKE2b-256 cc714bfae80df5423c515ae6bf2e6eb6aaf8a0efdf4fc61b29c005bcb9b91c7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kaptcha-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 296.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de597aed9e643df2c61073f22aefc8efa5000d07f08ac073ac54fd8aedbec40c
MD5 88fe8e9373d9aebb1b84e052f278b0fa
BLAKE2b-256 ab69a0440794852f5f0a856d1e16edb1f467054b5e8190ffc68126d88cebb40e

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