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

Recognize average color from image.

0.0.4 2019-06-16 18:29 UTC

This package is auto-updated.

Last update: 2024-06-17 05:14:55 UTC


README

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