dbeurive/color

This package contains implementations of a color picker.

1.0.3 2016-09-25 10:11 UTC

This package is not auto-updated.

Last update: 2025-01-08 21:27:01 UTC


README

This package implements a simple colour picker that allows the user to pick a colour by its name among a given list of colours.

The list of colours comes from Wikipedia.

License

The MIT License (MIT)

Copyright (c) 2016 Denis BEURIVE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Synopsis

    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";

Which will output:

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
)

Installation

Form the command line:

composer require dbeurive/color

Or, from within your file composer.json:

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

API

Colour codes come in multiple formats :

  • "html". For example "#0048BA"
  • "graphviz". For example "#0048BA"
  • "rgb". For example array(120, 150, 0)
  • "hsl". For example array(151, 100, 89)
  • "hsv". For example array(151, 21, 100)

Note: see Wikipedia for details.

Picker::setDefaultOutputFormat($inFormat)

Set the default output format. If not set, the default output format is 'html'. Valid formats' identifiers are:

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

Colour's getters