跳转到主要内容

根据WCAG2.1计算和调节颜色对比度的Python库

项目描述

颜色对比度

一个用于根据WCAG2.1计算和调节颜色对比度的Python库

PyPI - Version GitHub Tag GitHub Issues or Pull Requests

使用方法

使用以下命令将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

此示例使用了相同的背景和前景颜色,这是前后对比

Before After

贡献

要设置开发环境,请按照以下步骤操作。确保您已安装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

项目详情


发布历史 发布通知 | RSS源

下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分布

color_contrast-0.1.0.tar.gz (2.8 kB 查看哈希值)

上传时间:

构建分布

color_contrast-0.1.0-py3-none-any.whl (3.4 kB 查看哈希值)

上传时间 Python 3

由以下支持