andrey-helldar/which-color

此包已被弃用且不再维护。作者建议使用 dragon-code/which-color 包。

一个简单的辅助工具,帮助确定在单调颜色上哪种颜色显示文本更好。

4.0.0 2022-09-04 15:18 UTC

README

Which Color

一个简单的辅助工具,帮助确定在单调颜色上哪种颜色显示文本更好。

Stable Version Unstable Version Total Downloads Github Workflow Status License

安装

要获取包的最新版本,只需使用 Composer 依赖该项目

composer require dragon-code/which-color

当然,您也可以手动更新您的 require 部分,并运行 composer update 来更新

{
    "require": {
        "dragon-code/which-color": "^4.0"
    }
}

使用

该包可以帮助确定在单调颜色上哪种颜色显示文本更好。

use DragonCode\WhichColor\Facades\Color;

return Color::of('#000000')->lightIsBetter(); // returned `true`. A white text color is better for black background.
return Color::of('#ffffff')->darkIsBetter(); // returned `true`. A black text color is better for white background.

return Color::of('#ffffff')->lightIsBetter(); // returned `false`. White color is not the best for white background.
return Color::of('#000000')->darkIsBetter(); // returned `false`. Black color is not the best for black background.

您还可以使用转换器

use DragonCode\WhichColor\Services\Converter;

$converted = new Converter();

$rgb = $converted->hex2rgb('#fa000a'); // RGB object with [250, 0, 10]
// $rgb->red; // 250
// $rgb->green; // 0
// $rgb->blue; // 10
// $rgb->toArray(); // [250, 0, 10]

$converted->hex2rgb('#f5a'); // RGB object with [255, 85, 170]
$converted->hex2rgb('#ff55aa'); // RGB object with [255, 85, 170]

$converted->rgb2hex($rgb); // '#fa000a'
$converted->rgb2hex([250, 0, 10]); // '#fa000a'
$converted->rgb2hex(['red' => 250, 'green' => 0, 'blue' => 10]); // '#fa000a'
$converted->rgb2hex(['r' => 250, 'g' => 0, 'b' => 10]); // '#fa000a'

示例

map of colors

许可

此包根据 MIT 许可证 授权。