PHP code example of abyrate / colorist

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

    

abyrate / colorist example snippets


// Create an object in the standard way
$color = new \Abyrate\Colorist('rgb(55,191,0)');

// Create using static method
$color = \Abyrate\Colorist::create('rgb(55,191,0)');

$colorist->getChannel('red');   // get red channel
$colorist->getChannel('green'); // get green channel
$colorist->getChannel('blue');  // get blue channel
$colorist->getChannel('alpha'); // get alpha channel
$colorist->getChannel('hex');   // get hex code (e.g. #15af45)
$colorist->getChannel('hexa');  // get hex code with alpha (e.g. #15af4505)
$colorist->getChannel('name');  // get color name (e.g. orange)

$colorist->get('rgb');  // get rgb string (e.g. 15,156,10)
$colorist->get('rgba'); // get rgb string with alpha channel (e.g. 15,156,10,0.3)
$colorist->get('hex');  // get rgb in the hex format string (e.g. #15af45)
$colorist->get('hexa'); // get rgb with alpha channel in hex string (e.g. #15af4505)
$colorist->get('name'); // get color name (e.g. orange)

$colorist->setChannel('red', 15);           // set red channel
$colorist->setChannel('green', 20);         // set green channel
$colorist->setChannel('blue', 25);          // set blue channel
$colorist->setChannel('alpha', 0.3);        // set alpha channel
$colorist->setChannel('hex', '#004');       // set hex code
$colorist->setChannel('hexa', '#00112233'); // set hex code with alpha
$colorist->setChannel('name', 'orange');    // set color name

$colorist->set('rgb', 'rgb(0,15,36)');       // set rgb string
$colorist->set('rgba', 'rgb(0,15,36, 0.1)'); // set rgb string with alpha channel
$colorist->set('hex', '#123');               // set rgb in the hex format string
$colorist->set('hexa', '#1234');             // set rgb with alpha channel in hex string
$colorist->set('name', 'orange');            // set color name (e.g. orange)