artack/color

颜色辅助库,用于在RGB、CMYK、HSV、HST和HEX之间进行转换,并创建渐变。

0.6.0 2022-08-09 11:53 UTC

This package is auto-updated.

Last update: 2024-09-21 14:12:54 UTC


README

颜色转换和渐变(例如插值)。

Latest Release MIT License Total Downloads

由瑞士苏黎世的 ARTACK WebLab GmbH 开发。

特性

  • 提供 RGBCMYKHSVHSLHEX 的类表示。
  • 提供所有类表示之间的转换
  • 提供颜色之间的过渡(例如插值)
  • 提供清晰的异常处理,以便能够处理库异常
  • 与PHP >= 7和 >= 8兼容。

安装

您可以通过 Composer 安装此颜色库

$ composer require artack/color

使用方法

创建RGB类表示

$RGB = new RGB(0, 255, 0);
echo $RGB->getGreen(); // 255

将RGB类表示转换为HSV

$converter = Factory::createConverter();
$RGB = new RGB(0, 255, 0);

$HSV = $converter->convert($RGB, HSV::class);

根据给定的值(和最大值)获取两个颜色之间的渐变颜色

$transition = Factory::createTransition();
        
$RGBRed = new RGB(255, 0, 0); // red
$RGBGreen = new RGB(0, 255, 0); // green

$RGBInterpolated = $transition->interpolate(RGB::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow

// Interpolation will give better results when using HSV Transition. Colors get converted automatically if needed.
$HSVInterpolated = $transition->interpolate(HSV::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow