PHP code example of ryangjchandler / color

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

    

ryangjchandler / color example snippets


use RyanChandler\Color\Color;

$color = new Color(255, 255, 255);

$color = Color::new(255, 255, 255);

$color = Color::hex('#ffffff');

$color = Color::hsl(0, 0, 100);

$random = Color::random();

$color = Color::new(255, 255, 255);

$color->red; // 255
$color->green; // 255
$color->blue; // 255

Color::new(255, 255, 255)->toHex(); // #ffffff

[$h, $s, $l] = Color::new(255, 255, 255)->toHsl(); // [0, 0, 100]

Color::new(255, 255, 255)->toString(); // "(255, 255, 255)"

Color::new(255, 255, 255)->toString(true); // #ffffff

(string) Color::new(255, 255, 255); // "(255, 255, 255)"

Color::new(255, 255, 255)->toArray(); // [255, 255, 255]

[$r, $g, $b] = Color::new(255, 255, 255)->toArray();

$one = Color::new(0, 0, 220);
$two = Color::new(255, 0, 220);

Color::distanceBetween($one, $two); // 65_025

$one = Color::new(0, 0, 220);
$two = Color::new(255, 0, 220);

$one->distanceTo($two); // 65_025

$one = Color::rgb('#aaa');
$two = Color::rgb('#aaa');
$three = Color::rgb('#ccc');

Color::bothEqual($one, $two); // true
Color::bothEqual($one, $three); // false

$one = Color::rgb('#aaa');
$two = Color::rgb('#aaa');
$three = Color::rgb('#ccc');

$one->equals($two); // true
$one->equals($three); // false