PHP code example of wwaz / colormodel-php

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

    

wwaz / colormodel-php example snippets


use wwaz\Colormodel\Model\Hex;

$cmyk = (new Hex('#f00'))
    ->hue(180)
    ->toCMYK();

echo $cmyk->toString();    // 100,0,0,0
echo $cmyk->toHtml();      // cmyk(100,0,0,0)
echo $cmyk->toArray();     // [100, 0, 0, 0]

use wwaz\Colormodel\Model\Hex;

$red  = new Hex('#ff0000');
$blue = new Hex('#0000ff');

// 50/50 mix → purple
echo $red->mix($blue)->toString();        // 800080

// 75/25 mix (more red) → darker pink
echo $red->mix($blue, 0.25)->toString();  // BF0040

use wwaz\Colormodel\Model\RGB;
use wwaz\Colormodel\Scheme\Complementary;
use wwaz\Colormodel\Scheme\Triadic;
use wwaz\Colormodel\Scheme\Analogous;
use wwaz\Colormodel\Scheme\Tint;

$base = new RGB(255, 0, 0); // red

(new Complementary($base))->get(); // ['255,0,0', '0,255,255']
(new Triadic($base))->get();       // red + 2 harmonics
(new Analogous($base))->get();     // neighboring hues
(new Tint($base))->get();          // lighter variations

// Works with CMYK too — output stays in CMYK
use wwaz\Colormodel\Model\CMYKInt;
$cyan = new CMYKInt(100, 0, 0, 0);
(new Complementary($cyan))->get(); // ['100,0,0,0', '0,100,100,0']
bash
composer