farzai / color-palette
A robust PHP library for extracting, analyzing, and managing color palettes from images
Fund package maintenance!
parsilver
Requires
- php: ^8.1
- nyholm/psr7: ^1.8
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- symfony/http-client: ^6.4
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- pestphp/pest: ^2.20
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2024-12-16 16:18:48 UTC
README
A powerful PHP library for extracting color palettes from images and generating color themes. This package supports multiple image processing backends (GD and Imagick) and provides a rich set of color manipulation features.
Documentation
Features
- 🎨 Extract dominant colors from images using advanced color quantization
- 🖼️ Support for multiple image formats (JPEG, PNG, GIF, etc.)
- 🔄 Multiple image processing backends (GD and Imagick)
- 🎯 Generate color themes with surface, background, and accent colors
- 🌈 Color manipulation with RGB, HSL, and Hex support
- 📏 Color contrast ratio calculations
- 🎭 Automatic text color suggestions for optimal readability
- 🔍 Smart surface color recommendations based on color brightness
Requirements
- PHP 8.1 or higher
- GD extension or ImageMagick extension
- Composer
Installation
You can install the package via composer:
composer require farzai/color-palette
Basic Usage
use Farzai\ColorPalette\ImageFactory; use Farzai\ColorPalette\ColorExtractorFactory; use Farzai\ColorPalette\ColorPalette; // Create an image instance $imageFactory = new ImageFactory(); $image = $imageFactory->createFromPath('path/to/image.jpg'); // Create a color extractor $extractorFactory = new ColorExtractorFactory(); $extractor = $extractorFactory->create('gd'); // or 'imagick' // Extract colors to create a palette $colors = $extractor->extract($image); $palette = new ColorPalette($colors); // Get all colors $colors = $palette->getColors(); // Get suggested text color for a background $backgroundColor = $colors[0]; $textColor = $palette->getSuggestedTextColor($backgroundColor); // Get suggested surface colors $surfaceColors = $palette->getSuggestedSurfaceColors(); // Available keys: 'surface', 'background', 'accent', 'surface_variant'
Documentation
For detailed documentation, please visit our Documentation Site.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.