PHP code example of marijnvdwerf / material-palette

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

    

marijnvdwerf / material-palette example snippets


$manager = new ImageManager(array('driver' => 'imagick'));
$image = $manager->make('path/to/image.png');

$palette = Palette::generate($image);
echo $palette->getVibrantSwatch()->getColor();

$white = new RGBColor(1, 1, 1);
$black = new RGBColor(0, 0, 0);
$background = $palette->getVibrantSwatch()->getColor();

echo '<div style="background: ' . $background . '">';
if(AbstractColor::calculateContrast($background, $white) >= 3) {
    echo '<h1 style="color: white;">Palette</h1>';
} else {
    echo '<h1 style="color: black;">Palette</h1>';
}
echo '</div>';