decodelabs / spectrum
为PHP添加色彩
v0.2.3
2024-08-22 02:03 UTC
Requires
- php: ^8.1
- decodelabs/coercion: ^0.2
- decodelabs/exceptional: ^0.4
- decodelabs/glitch-support: ^0.4
Requires (Dev)
README
解析和操作颜色
Spectrum提供了一种简单但强大的系统,用于解析、检查、操作和导出颜色。
在DecodeLabs博客上获取新闻和更新。
安装
composer require decodelabs/spectrum
用法
通过RGB、HSL和HSV格式轻松加载和操作任何颜色。
use DecodeLabs\Spectrum\Color; $color = Color::create('#5AB3CD'); $color = Color::create('darkblue'); $color = Color::create('rgba(25,25,25,0.4)'); $color = Color::random(); $color->toHsl(); $color->lighten(0.3); // 30% lighter $color->setAlpha(0.5); // 50% opacity $color->toMidtone(); // Medium saturation and lightness echo $color; // Converts to appropriate CSS value $contrastColor = $color->contrastAgainst('pink'); $textColor = $color->getTextContrastColor();
许可
Spectrum遵循MIT许可证。有关完整的许可证文本,请参阅LICENSE。