decodelabs/spectrum

为PHP添加色彩

v0.2.3 2024-08-22 02:03 UTC

This package is auto-updated.

Last update: 2024-09-04 21:33:39 UTC


README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

解析和操作颜色

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