mscharley/colourist

该包已被弃用且不再维护。未建议替代包。

颜色操作库

1.1.2 2016-04-07 04:43 UTC

README

Circle CI Code Climate

Latest Stable Version Total Downloads

源代码: https://github.com/mscharley/colourist
作者: Matthew Scharley
贡献者: 在GitHub上查看贡献者
错误/支持: GitHub问题
版权 2015
许可: MIT许可
状态: 活动

概要

colourist 是一个针对 PHP 5.6+ 的小型库,有助于简化颜色和颜色转换的工作。

安装

$ composer require mscharley/colourist

使用

$colour = \Colourist\Colour::fromHex('#ffccaa');

// Automatically conversions to calculate values you need.
$h = $colour->hue(); 
$l = $colour->lightness();
$b = $colour->brightness();

// Distinguish between different types of saturation.
$sl = $colour->hslSaturation();
$sb = $colour->hsbSaturation();

// Explicit conversions if you need them. 
$hsl = $colour->toHSL();
$sl == $hsl->saturation();
// Colours are immutable - conversions are highly cached as a result.

// Freely convert between colour spaces as required.
$hsb = $colour->toHSB();
$colour->equals($hsb->toRGB()); // TRUE

注意事项

$colour = \Colourist\Colour::fromHex('#ffccaa');
$colour2 = \Colourist\Colour::fromHex('#aaccff');

// You must use ->equals() for comparing equality.
$colour->equals($colour2); // FALSE
$colour == $colour2; // stack overflow