Download the PHP package abderrahimghazali/color-palette-extractor without Composer
On this page you can find all versions of the php package abderrahimghazali/color-palette-extractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abderrahimghazali/color-palette-extractor
More information about abderrahimghazali/color-palette-extractor
Files in abderrahimghazali/color-palette-extractor
Package color-palette-extractor
Short Description Extract dominant colors from images with PHP
License MIT
Homepage https://github.com/abderrahimghazali/color-palette-extractor
Informations about the package color-palette-extractor
Color Palette Extractor
A fast and simple PHP library to extract dominant colors from images using GD extension.
Features
- 🎨 Extract dominant colors from any image
- 🚀 Fast processing with quality control
- 📊 Get color percentages and brightness analysis
- 🎯 Multiple output formats (HEX, RGB, HSL)
- 🔍 Smart similar color filtering
- 🖼️ Support for JPEG, PNG, GIF, WebP
- 💡 Complementary color generation
- 🎲 Zero dependencies (except GD)
Installation
Requirements:
- PHP 7.4+
- GD extension
Quick Start
Advanced Usage
Different Output Formats
Quality Control
Image Analysis
From Image Data
Method Reference
Core Methods
getDominant(int $count = 5, bool $excludeSimilar = true): array
Extract dominant colors from the image.
getPrimary(): string
Get the single most dominant color.
getPaletteWithPercentages(int $count = 5): array
Get colors with their percentage coverage.
getBrightness(): string
Determine if image is 'light' or 'dark'.
getComplementary(int $count = 5): array
Get complementary colors for the palette.
Configuration Methods
quality(int $quality): self
Set extraction quality (1-10, higher = more accurate but slower).
format(string $format): self
Set output format: 'hex', 'rgb', or 'hsl'.
Static Factory Methods
ColorPalette::fromImage(string $path): self
Create instance from image file path.
ColorPalette::fromData(string $data): self
Create instance from raw image data.
Real-World Examples
Website Theme Generator
Product Color Analysis
Automatic Color Tagging
Error Handling
Performance Tips
- Use quality control: Lower quality (1-3) for thumbnails, higher (7-10) for detailed analysis
- Process smaller images: The library automatically resizes, but smaller sources are faster
- Cache results: Color extraction is CPU-intensive, cache results when possible
- Exclude similar colors: Keep
excludeSimilar=truefor cleaner palettes
Supported Image Formats
- JPEG (
.jpg,.jpeg) - PNG (
.png) - GIF (
.gif) - WebP (
.webp) - if PHP compiled with WebP support
How It Works
- Image Loading: Uses GD to load the image
- Resizing: Automatically resizes to ~150px for performance
- Color Sampling: Samples pixels based on quality setting
- Color Grouping: Groups similar colors to reduce noise
- Frequency Analysis: Counts color occurrences
- Filtering: Removes rare colors and optionally similar colors
- Formatting: Converts to requested output format
License
MIT License. See LICENSE file for details.
Contributing
Pull requests welcome! Please ensure tests pass:
All versions of color-palette-extractor with dependencies
ext-gd Version *