PHP code example of emotality / laravel-color

1. Go to this page and download the library: Download emotality/laravel-color library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emotality / laravel-color example snippets


use Emotality\LaravelColor\Color;

$value = Color::parse('#ff2830')->functionName();
// or
$color = Color::parse('#ff2830');
$value1 = $color->functionName(); // see functions below
$value2 = $color->functionName(); // see functions below

use Emotality\LaravelColor\Color;

$value = Color::functionName('#ff2830'); // see functions below

$value = \Color::functionName('#ff2830'); // see functions below

$color = \Color::parse('#ff283080');
$alpha = $color->rgba()->alpha; // 0.502 (50%)

$black = '#000';
$is_dark = \Color::isDark($black); // true
$font_color = \Color::fontColor($black); // #ffffff

// #ff2830 has a brightness of 41 :
$font_color = \Color::fontColor('#ff2830', 30); // #000000
$font_color = \Color::fontColor('#ff2830', 50); // #ffffff

function hex(): string;
function hex8(): string;
function rgb(string $hex = null): object;
function rgba(string $hex = null): object;
function hsl(string $hex = null): object;
function hsv(string $hex = null): object;
function hue(string $hex = null): int;
function value(string $hex = null): int;
function luminance(string $hex = null): float;
function lightness(string $hex = null): int;
function brightness(string $hex = null): int;
function isDark(string $hex = null, int $contrast = null): bool;
function isLight(string $hex = null, int $contrast = null): bool;
function fontColor(string $hex = null, int $contrast = null): string;
function toJson(): string;
function toArray(): array;
function toObject(): object;
// more coming soon!

array:22 [
  "hex" => "#ff2830"
  "hexdec" => 16721968
  "hex8" => "#ff283080"
  "hex8dec" => 4280823935
  "red" => 1               // out of 1
  "green" => 0.15686       // out of 1
  "blue" => 0.18824        // out of 1
  "alpha" => 0.502         // out of 1
  "rgb" => array:3 [
    "red" => 255           // out of 255
    "green" => 40          // out of 255
    "blue" => 48           // out of 255
  ]
  "rgba" => array:4 [
    "red" => 255           // out of 255
    "green" => 40          // out of 255
    "blue" => 48           // out of 255
    "alpha" => 0.502       // out of 1
  ]
  "hsl" => array:3 [
    "hue" => 358           // out of 360
    "saturation" => 100    // out of 100
    "lightness" => 58      // out of 100
  ]
  "hsv" => array:3 [
    "hue" => 358           // out of 360
    "saturation" => 84     // out of 100
    "value" => 100         // out of 100
  ]
  "hue" => 358             // out of 360
  "value" => 100           // out of 100
  "luminance" => 22.99     // out of 100
  "lightness" => 58        // out of 100
  "brightness" => 41       // out of 100
  "dark" => true
  "light" => false
  "font_color" => "#ffffff"
  "shades" => array:21 [
    0 => "#ff2830"
    5 => "#f2262e"
    10 => "#e6242b"
    15 => "#d92229"
    20 => "#cc2026"
    25 => "#bf1e24"
    30 => "#b31c22"
    35 => "#a61a1f"
    40 => "#99181d"
    45 => "#8c161a"
    50 => "#801418"
    55 => "#731216"
    60 => "#661013"
    65 => "#590e11"
    70 => "#4d0c0e"
    75 => "#400a0c"
    80 => "#33080a"
    85 => "#260607"
    90 => "#1a0405"
    95 => "#0d0202"
    100 => "#000000"
  ]
  "tints" => array:21 [
    0 => "#ff2830"
    5 => "#ff333a"
    10 => "#ff3e45"
    15 => "#ff484f"
    20 => "#ff5359"
    25 => "#ff5e64"
    30 => "#ff696e"
    35 => "#ff7378"
    40 => "#ff7e83"
    45 => "#ff898d"
    50 => "#ff9498"
    55 => "#ff9ea2"
    60 => "#ffa9ac"
    65 => "#ffb4b7"
    70 => "#ffbfc1"
    75 => "#ffc9cb"
    80 => "#ffd4d6"
    85 => "#ffdfe0"
    90 => "#ffeaea"
    95 => "#fff4f5"
    100 => "#ffffff"
  ]
]