richarddobron / php-avg-color-picker
The PHP Average Color Picker Library
1.2.0
2025-08-10 17:42 UTC
Requires
- php: ^8.0
- ext-fileinfo: *
- ext-gd: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9.6|^10.0
This package is auto-updated.
Last update: 2025-08-11 07:48:15 UTC
README
A simple, lightweight and fast PHP function that uses the GD library to extract the average color of an image.
Note
Keep in mind that this function will return the average color of an image, not the main color.
📖 Requirements
- PHP 7.0 or higher
- Composer is required for installation
- PHP Extensions:
ext-mbstring
,ext-gd
,ext-fileinfo
,ext-ctype
📦 Installation
Install the library using Composer:
$ composer require richarddobron/php-avg-color-picker
👀 Example
Input - The Image Path
Output - The Image Average Color
⚡️ Quick Start
Here’s how to use the library to determine the average color of an image:
<?php use Dobron\AvgColorPicker\Gd\AvgColorPicker; $imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb('image.png'); // or $imageAvgRgbColor = (new AvgColorPicker)->getImageAvgRgb(imagecreatefrompng('image.png')); var_dump($imageAvgRgbColor); // array(255, 255, 255)
<?php use Dobron\AvgColorPicker\Gd\AvgColorPicker; $imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex('image.gif'); // or $imageAvgHexColor = (new AvgColorPicker)->getImageAvgHex(imagecreatefromgif('image.gif')); var_dump($imageAvgHexColor); // string(7) "#ffffff"
🧪 Testing
$ composer tests
🤝 Contributing
Please see CONTRIBUTING for details.
⚖️ License
This repository is MIT licensed, as found in the LICENSE file.