Skip to content

Recognize average color from image. Alter average color by saturation or lightness.

License

Notifications You must be signed in to change notification settings

hracik/php-recognize-average-color-from-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recognize color from image

Recognize average color from image - can be external image URL or local file.

Getting Started

These instructions will get you a copy of the project up and running

Installing

Install with Composer

composer require hracik/php-recognize-average-color-from-image

Usage

If you want to alter average color, e.g. to use the color on web dark/light designs, you can provide custom saturation and lightness within options.

use Hracik\RecognizeAverageColorFromImage;

//can be path to local image or URL
$path = 'https://raw.githubusercontent.com/hracik/php-recognize-average-color-from-image/master/example/example2.jpg;
//possible return options are: RETURN_STRING_HEX, RETURN_STRING_RGB, RETURN_ARRAY_RGB, RETURN_ARRAY_RGB_NORMALIZED, RETURN_ARRAY_HSL
$return = RecognizeAverageColorFromImage::RETURN_STRING_HEX;
//only accepted keys are saturation and lightness
$options = ['saturation' => 0.6, 'lightness' => 0.3];
$color = RecognizeAverageColorFromImage::getAverageColor($path, $return);
echo $color;

Output #707A1E. Same image without options return color #838B45.

Or just get counted average without options attribute.

use Hracik\RecognizeAverageColorFromImage;

$path = 'https://raw.githubusercontent.com/hracik/php-recognize-average-color-from-image/master/example/example3.jpg;
$color = RecognizeAverageColorFromImage::getAverageColor($path, RecognizeAverageColorFromImage::RETURN_STRING_HEX);
echo $color;

Output #658FAD.

Running the tests

Run

./vendor/bin/phpunit --bootstrap vendor/autoload.php tests

For Windows platforms

./vendor/bin/phpunit.bat --bootstrap vendor/autoload.php tests

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Andrej Lahucky - Initial work - Hracik

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

  • PurpleBooth

About

Recognize average color from image. Alter average color by saturation or lightness.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages