owen-jones/color-kit
最新稳定版本:1.0.1
Composer 安装命令:
composer require owen-jones/color-kit
包简介
A PHP library for manipulating accessible color combinations.
README 文档
README
ColorKit is a PHP library for handling and manipulating colors. It provides utilities for generating color triads and checking color contrast accessibility.
Installation
To install ColorKit, run:
composer require owen-jones/color-kit
Usage
Generating Color Triads
To get a color triad based on a base color:
require 'vendor/autoload.php'; use OwenJones\ColorKit\ColorKit; $baseColor = '#3498db'; $triad = ColorKit::getColorTriad($baseColor); print_r($triad); // ['#3498db', '#db3434', '#34db34']
The first 2 colors are guaranteed to be accessible. The third is not.
Checking Color Contrast
To check if the contrast between two colors is accessible (contrast ratio of at least 4.5):
use OwenJones\ColorKit\ColorKit; $color1 = '#3498db'; $color2 = '#ffffff'; $isAccessible = ColorKit::isContrastAccessible($color1, $color2); echo $isAccessible ? 'Accessible' : 'Not Accessible';
Methods
getColorTriad(string $baseColor): array
Generates a color triad based on the base color.
- Parameters:
string $baseColor: Hex value of the base color.
- Returns:
string[]: An array containing the base color and two other colors.
isContrastAccessible(string $color1, string $color2): bool
Checks if the contrast between two colors is accessible.
- Parameters:
string $color1: Hex value of the first color.string $color2: Hex value of the second color.
- Returns:
bool:trueif the contrast ratio is at least 4.5,falseotherwise.
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-04