andrey-helldar / black-or-white-text-color
4.0.0
2022-09-04 15:18 UTC
Requires
- php: ^8.1
- dragon-code/simple-dto: ^2.3
- dragon-code/support: ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^6.1
README
一个简单的助手,帮助确定在单色调上文字的哪种颜色看起来更好。
安装
要获取软件包的最新版本,只需使用 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'
示例
许可证
本软件包根据 MIT 许可证 许可。