americanart / studio
Extract colors from an image and other color utilities.
1.0.0
2022-01-18 16:53 UTC
Requires
- php: ^7.3|^8.0
- ext-gd: *
Requires (Dev)
- phpunit/phpunit: ^8.5
- spatie/ray: ^1.33
- squizlabs/php_codesniffer: ^3.0
- symfony/var-dumper: ^4.3
README
Extract colors from an image and other color utilities.
Install
Install with composer:
composer require americanart/studio
Dependencies
- requires PHP 7.3 or greater.
Functionality
- Find the english language name of a (HEX) color.
- Convert colors between RGB, HSV, XYZ, and Lab color spaces.
- Compare colors.
- Extract colors as a palette from an image.
Usage
Get the RGB values of a color
<?php
$color = \AmericanArt\Studio\ColorFactory::new()->createFromHex('#4682b4');
$rgb = $color->getRgb();
echo "Red: {$rgb['R']}, Green: {$rgb['G']}, Blue: {$rgb['B']}";
// output: "Red: 70, Green: 130, Blue: 180"
Get the closest CSS4 color to a given color
<?php
$picker = new AmericanArt\Studio\ColorPicker();
$color = \AmericanArt\Studio\ColorFactory::new()->createFromRgb(131, 246, 0);
$closestColor = $picker->getClosestColor($color);
echo $closestColor->getName();
// output: "lawngreen"
Get the 5 most common colors from an image
<?php
$picker = new AmericanArt\Studio\ColorPicker();
$url = 'https://s3.amazonaws.com/assets.saam.media/files/styles/x_large/s3/files/images/1991/SAAM-1991.61_2.jpg';
$colors = $picker->getColorsFromFile($url, 5);
foreach($colors as $color) {
echo $color->getHex() . ' ';
}
// output: #dd290e #7d0000 #01168b #1563eb #3fb666