根据WCAG2.1计算和调节颜色对比度的Python库
项目描述
颜色对比度
一个用于根据WCAG2.1计算和调节颜色对比度的Python库
使用方法
使用以下命令将color-contrast
安装到您的Python环境中
pip install color-contrast
安装后,您可以使用该项目如下
from colour import Color
from color_contrast import AccessibilityLevel, check_contrast
bg = Color("#123456")
check_contrast("#404040", bg, level=AccessibilityLevel.AA18) # True
check_contrast("#404040", bg, level=AccessibilityLevel.AA) # False
check_contrast("white", bg, level=AccessibilityLevel.AAA) # True
check_contrast(Color(hsl=(1, 1, 1)), bg) # True
或者,如果您想自动调节颜色
from color_contrast import modulate, ModulationMode
modulate("5d3eb2", "5d3eb2", mode=ModulationMode.BOTH)
# Returns:
# <Color: #32215f>, <Color: #9e89d6>, true
此示例使用了相同的背景和前景颜色,这是前后对比
贡献
要设置开发环境,请按照以下步骤操作。确保您已安装poetry。
# Clone the repository
git clone git@github.com:ZugBahnHof/color-contrast.git
cd color-contrast
# Activate the virtual environment
poetry shell
# Install the requirements
poetry install
# Activate the commit hooks
pre-commit install
有用的命令
# Run the linter
ruff check
# Reformat
ruff check --fix
ruff format
# Run the test cases
python -m unittest tests
项目详情
关闭
color_contrast-0.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cb9cd0c09b3000e4ebeefe5da3c0f81ca7c9f5d60212b7473f1c2b41eb7e4b81 |
|
MD5 | 9559390e08e2d8a1f60b8a2536ff9852 |
|
BLAKE2b-256 | 4633c06f94b4eb048c59f0ad2640d822eb33e01bfb128a27b33a65fe93f47419 |
关闭
color_contrast-0.1.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fcbf3e3bb9f4ad87af95acf9945f8505aa668f660d5a20843e7d7d65fda21756 |
|
MD5 | e4d6b6cc9e382550fe3a61a0fca8ab3f |
|
BLAKE2b-256 | 7054d85287d9550f649a7034655d8c5918244f979efad6e70a67dfbfacbfae38 |