1. Go to this page and download the library: Download jonaskohl/color-extractor 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/ */
jonaskohl / color-extractor example snippets
use JonasKohl\ColorExtractor\Color;
use JonasKohl\ColorExtractor\ColorExtractor;
use JonasKohl\ColorExtractor\Palette;
$palette = Palette::fromFilename('./some/image.png');
// $palette is an iterator on colors sorted by pixel count
foreach($palette as $color => $count) {
// colors are represented by integers
echo Color::fromIntToHex($color), ': ', $count, "\n";
}
// it offers some helpers too
$topFive = $palette->getMostUsedColors(5);
$colorCount = count($palette);
$blackCount = $palette->getColorCount(Color::fromHexToInt('#000000'));
// an extractor is built from a palette
$extractor = new ColorExtractor($palette);
// it defines an extract method which return the most “representative” colors
$colors = $extractor->extract(5);
// we set a white background so fully transparent colors will be added as white in the palette
// pure red #FF0000 at 50% opacity will be stored as #FF8080 as it would be perceived
$palette = Palette::fromFilename('./some/image.png', Color::fromHexToInt('#FFFFFF'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.