dragon-code/which-color

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

v4.0.0 2022-09-04 15:18 UTC

This package is auto-updated.

Last update: 2024-09-16 18:20:25 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许可证授权。