PHP code example of franckysolo / php-color

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

    

franckysolo / php-color example snippets



hpColor\Color;

// Create an instance
$black = new Color(); // will generate a black color default
$white = new Color(255, 255, 255); // will generate a white color
$transparent = new Color(255, 255, 255, 127); // will generate a transparent color

// with static methods
$red  = Color::fromArray([255, 0, 0]);
$alpha_red  = Color::fromArray([100, 255, 0, 0]);
$blue = Color::fromHex('0000ff');
$aqua = Color::fromInt(Color::AQUA);


hpColor\Color;

// Create an instance
$white = new Color(255, 255, 255);
$aplha_red = new Color(255, 0, 0, 100);

// Reading colors
$intColor = $white->toInt() // returns integer 16777215
$arrayColor = $white->toArray() // returns array [0,255,255,255]
$hexColor = $white->toHex() // returns String  'ffffff'
$cssColor = $white->toHex(true) // returns String  '#ffffff'
echo $white; // display String 'rgb(255,255,255);'
echo $aplha_red; // display String 'rgba(255,255,255, 0.2);'


// An example of Color constants using gd
or(100, 100);
imagefill($image, 0, 0, Color::TRANSPARENT);
imagefilledrectangle($image, 25, 25, 75, 75, Color::AQUA);
imagepng($image);
imagedestroy($image);
header('Content-type: image/png');


hpColor\Color;
$green = Color::fromInt(Color::GREEN);
$blue = Color::fromInt(Color::BLUE);
$red = Color::fromInt(Color::RED);
$orange = Color::fromInt(Color::ORANGE);
$yellow = Color::fromInt(Color::YELLOW);
$lightGreen = Color::fromArray([100,0,255,0]);
$values = [$green, $blue, $red, $orange, $yellow, $lightGreen];
$json = [];
foreach ($values as $value) {
	$json[] = $value->__toString();
}


hpColor\Color;
$green = Color::fromInt(Color::GREEN);
$blue = Color::fromInt(Color::BLUE);
$red = Color::fromInt(Color::RED);
$orange = Color::fromInt(Color::ORANGE);
$yellow = Color::fromInt(Color::YELLOW);
$lightGreen = Color::fromArray([100,0,255,0]);


hpColor\Color;
$green = Color::fromInt(Color::GREEN);
$blue = Color::fromInt(Color::BLUE);
$red = Color::fromInt(Color::RED);
$orange = Color::fromInt(Color::ORANGE);
$yellow = Color::fromInt(Color::YELLOW);
$alphaGreen = Color::fromArray([120,0,255,0]);
$opaqueGreen = $alphaGreen->toHex(true);

composer