PHP code example of tooleks / php-avg-color-picker

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

    

tooleks / php-avg-color-picker example snippets




use Tooleks\Php\AvgColorPicker\Gd\AvgColorPicker;

$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgbByPath($imagePath);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgbByResource($gdImageResource);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb($imagePath);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb($gdImageResource);

// The `$imageAvgRgbColor` variable contains the average color of the given image in RGB format (array)[255, 255, 255].



use Tooleks\Php\AvgColorPicker\Gd\AvgColorPicker;

$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHexByPath($imagePath);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHexByResource($gdImageResource);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex($imagePath);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex($gdImageResource);

// The `$imageAvgHexColor` variable contains the average color of the given image in HEX format (string)"#fffff".

<div style="background-color: <?= $imageAvgHexColor