Kaptcha:python 验证码生成工具
简述
优点
- 调用简单
- 高度自定义
- 生成快速
示例
| 类型(干扰都为5) | 内容 | 图片 |
|---|---|---|
| 字母数字混合型 | 7w8W | |
| 数字型 | 5244 | |
| 字母型 | Ehqx | |
| 增强型 | wd81 | |
| 边缘凸显 | bpCk | |
| 浮雕效果 | MkT6 | |
| 轮廓 | qXLT | |
| GIF动态图 | 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)
-
数英混合
import kaptcha x, y = kaptcha.Captcha().letter_digit() print(x, y)
-
纯英文
import kaptcha x, y = kaptcha.Captcha().letter() print(x, y)
-
纯数字
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
Metadata
Release files for kaptcha 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kaptcha-1.0.1.tar.gz | 296.8 kB | Without provenance | Details for kaptcha-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kaptcha-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for kaptcha-1.0.1-py3-none-any.whl |
Total release size: 592.7 kB
Release files / kaptcha-1.0.1.tar.gz
| Download URL | kaptcha-1.0.1.tar.gz |
|---|---|
| Size | 296.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d603b66872c77a6cc9d7542844b7e6c10877bad7cc33a3db9eb0ab362c77401d
|
|
BLAKE2b-256 checksum How to use checksums |
cc714bfae80df5423c515ae6bf2e6eb6aaf8a0efdf4fc61b29c005bcb9b91c7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / kaptcha-1.0.1-py3-none-any.whl
| Download URL | kaptcha-1.0.1-py3-none-any.whl |
|---|---|
| Size | 296.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de597aed9e643df2c61073f22aefc8efa5000d07f08ac073ac54fd8aedbec40c
|
|
BLAKE2b-256 checksum How to use checksums |
ab69a0440794852f5f0a856d1e16edb1f467054b5e8190ffc68126d88cebb40e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for kaptcha 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.