PHP code example of scripturadesign / color

1. Go to this page and download the library: Download scripturadesign/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/ */

    

scripturadesign / color example snippets

 php
$hex = new \Scriptura\Color\Types\HEX('ff0000'); // New HEX color
$hex = new \Scriptura\Color\Types\HEX('ff0000', '#{code}'); // New HEX color with template
echo $hex->code(); // 'FF0000'
echo $hex; // '#FF0000'
echo $hex->withTemplate('color: #{code};'); // 'color: #FF0000;'

$hex  = $hex->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $hex->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $hex->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $hex->to256(); // Convert the color to \Scriptura\Color\Types\C256
 php
$rgb = new \Scriptura\Color\Types\RGB(255, 0, 0); // New RGB color
$rgb = new \Scriptura\Color\Types\RGB(255, 0, 0, '{red},{green},{blue}'); // New RGB color with template
echo $rgb->red(); // 255
echo $rgb->green(); // 0
echo $rgb->blue(); // 0
echo $rgb->rgb(); // [255, 0, 0]
echo $rgb; // '255,0,0'
echo $rgb->withTemplate('color: rgb({red}, {green}, {blue});'); // 'color: rgb(255, 0, 0);'

$rgb = $rgb->withRed(0); // New instance with red set to 0
$rgb = $rgb->withGreen(255); // New instance with green set to 255
$rgb = $rgb->withBlue(255); // New instance with blue set to 255

$hex  = $rgb->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $rgb->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $rgb->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $rgb->to256(); // Convert the color to \Scriptura\Color\Types\C256
 php
$c256 = new \Scriptura\Color\Types\C256(196); // New 256 color
$c256 = new \Scriptura\Color\Types\C256(196, '{code}'); // New 256 color with template
echo $c256->code(); // 196
echo $c256; // '196'
echo $c256->withTemplate('\e[48;{code}m'); // '\e[48;196m'

$hex  = $c256->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $c256->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $c256->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $c256->to256(); // Convert the color to \Scriptura\Color\Types\C256