https://github.com/tooleks/php-avg-color-picker
The PHP Average Color Picker Package
https://github.com/tooleks/php-avg-color-picker
average avg color hex php picker rgb
Last synced: about 1 year ago
JSON representation
The PHP Average Color Picker Package
- Host: GitHub
- URL: https://github.com/tooleks/php-avg-color-picker
- Owner: tooleks
- License: mit
- Created: 2017-05-13T12:21:40.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-15T18:06:22.000Z (almost 4 years ago)
- Last Synced: 2025-03-27T14:52:45.739Z (over 1 year ago)
- Topics: average, avg, color, hex, php, picker, rgb
- Language: PHP
- Homepage: https://packagist.org/packages/tooleks/php-avg-color-picker
- Size: 267 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# The PHP Average Color Picker Library
The package provides the library for picking an average color from the given image. Currently it supports `image/png`, `image/jpeg`, `image/gif` image MIME types.
## Example
### Input - The Image Path
[The Image Path](https://github.com/tooleks/php-avg-color-picker/tree/master/resources/input.jpg)

### Output - The Image Average Color
[The Image Average Color](https://github.com/tooleks/php-avg-color-picker/tree/master/resources/output.jpg)

## Requirements
"php": "^7.0",
"ext-mbstring": "\*",
"ext-gd": "\*"
## Installation
### Package Installation
Execute the following command to get the latest version of the package:
```shell
composer require tooleks/php-avg-color-picker
```
## Usage Examples
```php
getImageAvgRgbByPath($imagePath);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgbByResource($gdImageResource);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb($imagePath);
// or
$imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb($gdImageResource);
// The `$imageAvgRgbColor` variable contains the average color of the given image in RGB format (array)[255, 255, 255].
```
```php
getImageAvgHexByPath($imagePath);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHexByResource($gdImageResource);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex($imagePath);
// or
$imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex($gdImageResource);
// The `$imageAvgHexColor` variable contains the average color of the given image in HEX format (string)"#fffff".
```
You can use the calculated value to show the average image color in its container before the image is loaded.
```php
```
## Tests
Execute the following command to run tests:
```shell
./vendor/bin/phpunit
```