dbeurive/color

此包包含颜色选择器的实现。

1.0.3 2016-09-25 10:11 UTC

This package is not auto-updated.

Last update: 2024-09-18 19:49:15 UTC


README

此包实现了一个简单的颜色选择器,用户可以在给定的颜色列表中通过颜色名称选择颜色。

颜色列表来自 维基百科

许可证

MIT 许可证 (MIT)

版权所有 (c) 2016 Denis BEURIVE

特此授予任何获得此软件及其相关文档副本(以下简称“软件”)的人免费使用权,不受任何限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向提供软件的人授予此类权利,但受以下条件约束

上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论此类索赔、损害或其他责任是基于合同、侵权或其他方式引起的,与软件或其使用或任何其他方式有关。

概述

    use dbeurive\Color\Picker;

    print 'HTML code for the color "Absolute Zero": ' . Picker::absoluteZero() . "\n";
    print 'HTML code for the color "Aero Blue": ' . Picker::aeroBlue() . "\n";

    print 'GraphViz code for the color "Absolute Zero": ' . Picker::absoluteZero('graphviz') . "\n";
    print 'GraphViz code for the color "Aero Blue": ' . Picker::aeroBlue('graphviz') . "\n";

    Picker::setDefaultOutputFormat('rgb');

    print 'RGB triplet for the color "Absolute Zero": ' .  print_r(Picker::absoluteZero(), true) . "\n";
    print 'RGB triplet for the color "Aero Blue": ' . print_r(Picker::aeroBlue(), true) . "\n";

    Picker::setDefaultOutputFormat('hsl');

    print 'HSL triplet for the color "Absolute Zero": ' .  print_r(Picker::absoluteZero(), true) . "\n";
    print 'HSL triplet for the color "Aero Blue": ' . print_r(Picker::aeroBlue(), true) . "\n";

    Picker::setDefaultOutputFormat('hsv');

    print 'HSV triplet for the color "Absolute Zero": ' .  print_r(Picker::absoluteZero(), true) . "\n";
    print 'HSV triplet for the color "Aero Blue": ' . print_r(Picker::aeroBlue(), true) . "\n";

将输出

HTML code for the color "Absolute Zero": #0048BA
HTML code for the color "Aero Blue Zero": #C9FFE5
GraphViz code for the color "Absolute Zero": #0048BA
GraphViz code for the color "Aero Blue Zero": #C9FFE5
RGB triplet for the color "Absolute Zero": Array
(
    [0] => 0
    [1] => 28
    [2] => 73
)

RGB triplet for the color "Aero Blue Zero": Array
(
    [0] => 79
    [1] => 100
    [2] => 90
)

HSL triplet for the color "Absolute Zero": Array
(
    [0] => 217
    [1] => 100
    [2] => 37
)

HSL triplet for the color "Aero Blue Zero": Array
(
    [0] => 151
    [1] => 100
    [2] => 89
)

HSV triplet for the color "Absolute Zero": Array
(
    [0] => 217
    [1] => 100
    [2] => 73
)

HSV triplet for the color "Aero Blue Zero": Array
(
    [0] => 151
    [1] => 21
    [2] => 100
)

安装

从命令行

composer require dbeurive/color

或,从文件 composer.json 内部

"require": {
    "dbeurive/color": "*"
}

API

颜色代码有多个格式

  • "html"。例如 "#0048BA"
  • "graphviz"。例如 "#0048BA"
  • "rgb"。例如 array(120, 150, 0)
  • "hsl"。例如 array(151, 100, 89)
  • "hsv"。例如 array(151, 21, 100)

注意:有关详细信息,请参阅 维基百科

Picker::setDefaultOutputFormat($inFormat)

设置默认输出格式。如果未设置,默认输出格式为 'html'。有效格式的标识符包括

  • "html"
  • "graphviz"
  • "rgb"
  • "hsl"
  • "hsv"

颜色的获取器