PHP code example of votemike / color

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

    

votemike / color example snippets


// Construct with R,G,B,A values. Alpha may be ommited and will default to 1
$color = new Color(0, 100, 200);
$color = new Color(0, 100, 200, 0.5);
  
// Create Color object from string
$color = Color::fromRgba('0,0,0,0');
$color = Color::fromRgb('0,0,0');
$color = Color::fromHex('000000');
$color = Color::fromShortHex('F00');
$color = Color::fromX11('rebeccapurple');
$color = Color::fromHsla('180, 0%, 85%, 1');
$color = Color::fromHsl('0, 100%, 10%');
  
// Get strings for different formats
$color = new Color(255, 255, 255, 1);
$color->toHex(); // #ffffff
$color->toRgba(); // rgba(255,255,255,1)
$color->toX11(); // white
  
// If a color can't be translated, it will be an empty string
$color = new Color(0, 0, 0, 0.5);
$color->toHex(); // ''
$color->toRgba(); // rgba(255,255,255,0.5)
$color->toX11(); // ''