Last active
May 10, 2017 08:11
-
-
Save fosron/9ea8f3278c5932f383e9d60a95936f12 to your computer and use it in GitHub Desktop.
color-extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<<<CONFIG | |
packages: | |
- "league/color-extractor: 0.3.*" | |
CONFIG; | |
use League\ColorExtractor\Color; | |
use League\ColorExtractor\ColorExtractor; | |
use League\ColorExtractor\Palette; | |
$palette = League\ColorExtractor\Palette::fromFilename('http://ca.france.fr/sites/default/files/imagecache/ATF_Image_bandeau_v2/la_france_cote_nature_6.jpg'); | |
// $palette is an iterator on colors sorted by pixel count | |
/*foreach($palette as $color => $count) { | |
echo Color::fromIntToHex($color), ': ', $count, "\n"; | |
}*/ | |
// it offers some helpers too | |
$topFive = $palette->getMostUsedColors(5); | |
$colorCount = count($palette); | |
$blackCount = $palette->getColorCount(League\ColorExtractor\Color::fromHexToInt('#000000')); | |
// an extractor is built from a palette | |
$extractor = new League\ColorExtractor\ColorExtractor($palette); | |
// it defines an extract method which return the most “representative” colors | |
$colors = $extractor->extract(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment