PHP code example of andrey-helldar / which-color

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

    

andrey-helldar / which-color example snippets


use DragonCode\WhichColor\Facades\Color;

return Color::of('#000000')->lightIsBetter(); // returned `true`. A white text color is better for black background.
return Color::of('#ffffff')->darkIsBetter(); // returned `true`. A black text color is better for white background.

return Color::of('#ffffff')->lightIsBetter(); // returned `false`. White color is not the best for white background.
return Color::of('#000000')->darkIsBetter(); // returned `false`. Black color is not the best for black background.

use DragonCode\WhichColor\Services\Converter;

$converted = new Converter();

$rgb = $converted->hex2rgb('#fa000a'); // RGB object with [250, 0, 10]
// $rgb->red; // 250
// $rgb->green; // 0
// $rgb->blue; // 10
// $rgb->toArray(); // [250, 0, 10]

$converted->hex2rgb('#f5a'); // RGB object with [255, 85, 170]
$converted->hex2rgb('#ff55aa'); // RGB object with [255, 85, 170]

$converted->rgb2hex($rgb); // '#fa000a'
$converted->rgb2hex([250, 0, 10]); // '#fa000a'
$converted->rgb2hex(['red' => 250, 'green' => 0, 'blue' => 10]); // '#fa000a'
$converted->rgb2hex(['r' => 250, 'g' => 0, 'b' => 10]); // '#fa000a'