Download the PHP package farzai/color-palette without Composer

On this page you can find all versions of the php package farzai/color-palette. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package color-palette

Color Palette PHP

Latest Version on Packagist Tests Total Downloads

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.

Table of Contents

Features

Requirements

Installation

Install the package via composer:

Loading images from URLs (optional)

Extracting colors from local files has no HTTP dependencies. To load images from remote URLs, also install any PSR-18 HTTP client — it is auto-discovered, no wiring required:

symfony/http-client is recommended because the loader configures it to not follow redirects, so every redirect hop is re-validated against the SSRF rules. You can also pass your own PSR-18 client / PSR-17 factory to ImageLoaderFactory or ImageLoader.

Quick Start

Simple Approach (Recommended)

Extract colors in one line:


Builder Pattern (Flexible)

Chain multiple operations with the builder:


Advanced (Full Control)

Use individual components for dependency injection and custom configuration:

Core Concepts

ImageFactory

Load images from files for color extraction.

ColorExtractor

Extract dominant colors using color quantization. Two drivers available:

ColorPalette

A collection of extracted colors with array-like access.

Color Objects

Immutable objects supporting multiple color spaces.

Note: Color objects are immutable - methods always return new instances.

Common Use Cases

1. Generate Website Theme from Logo

Extract colors from your logo and create a complete theme:

2. Create Accessible Color Scheme (WCAG Compliant)

Ensure your color combinations meet accessibility standards:

3. Generate CSS Variables from Image

Create CSS custom properties from image colors:

4. Generate Color Schemes

Create color harmonies using built-in schemes:

API Reference

Working with Images

Simple: ColorPalette::fromImage()

Parameters:

Returns: ColorPalette

Advanced: ImageFactory

Extracting Color Palettes

Simple: ColorPalette::fromImage()

Advanced: Using ColorExtractor

Color Format Conversions

The Color class supports multiple color space conversions:

Creating Colors

Converting Colors

Color Manipulation

All manipulation methods return new Color instances (immutable):

Color Analysis

WCAG Contrast Requirements:

Theme Generation

ColorPalette::getSuggestedSurfaceColors()

Get a complete color theme from the palette:

Returns: Array with keys:

This is a lightweight heuristic helper that returns a plain array. For a typed, validated 5-role theme, use Theme (below).

Typed themes — Theme

Theme is a value object that always defines the five roles primary, secondary, accent, background, surface; its getters never throw.

ColorPalette::getSuggestedTextColor()

Get optimal text color (black or white) for a background:

Parameters:

Returns: ColorInterface - Either black (#000000) or white (#ffffff) based on contrast

Troubleshooting & FAQ

Which image processing extension should I use?

GD (Recommended for most users):

Imagick (For better accuracy):

How do I check which extension is installed?

Or use the built-in checker:

How do I install GD or Imagick?

Ubuntu/Debian:

macOS (Homebrew):

Restart your web server after installation!

The colors extracted don't look right

  1. Try the other driver - Imagick often produces more accurate results:

  2. Extract more colors - Increase the count for better variety:

  3. Check image quality - Low quality or heavily compressed images may produce poor results

  4. Image has many similar colors - This is expected behavior; the library finds dominant colors

Memory issues with large images

For very large images (> 5MB), consider:

  1. Resize before processing (using GD or Imagick directly)
  2. Increase PHP memory limit in php.ini:

  3. Use GD instead of Imagick (lower memory usage)

Supported image formats

GD Driver:

Imagick Driver:

Why are my Color objects not changing?

Color objects are immutable. Methods return new instances:

How many colors should I extract?

More colors = more processing time and memory usage.

Security

HTTP Client Security

The library implements comprehensive security measures when loading images from URLs to protect against SSRF (Server-Side Request Forgery) and other attacks.

SSRF Protection

All remote URLs are validated before making HTTP requests:

Blocked Protocols:

Blocked IP Addresses:

Choosing an HTTP Client (redirect safety)

The loader follows redirects itself and re-validates every hop against the SSRF rules above — but only if the underlying PSR-18 client does not follow redirects on its own. The default does this correctly: when symfony/http-client is installed, the factory configures it with max_redirects = 0.

⚠️ A different PSR-18 client (e.g. Guzzle) may follow redirects internally by default, which bypasses the per-hop re-validation — a redirect from a public URL to an internal address would be followed before the loader can check it. When accepting user-supplied URLs, prefer symfony/http-client, or inject a client configured not to follow redirects:

File Size Limits

Downloaded files are limited to 10MB by default to prevent denial-of-service attacks:

Files are streamed in chunks (8KB at a time) and validated during download, not loaded entirely into memory.

MIME Type Validation

Remote files are validated to ensure they're actual images:

  1. Content-Type Header: Checked if present in HTTP response
  2. File Detection: Actual file content verified using finfo after download

Only these MIME types are accepted:

HTTP Client Configuration

Customize HTTP client behavior for security and performance:

Security Recommendations:

  1. Keep maxRedirects: 0 - Redirects can bypass SSRF protection
  2. Keep verifySsl: true - Prevents man-in-the-middle attacks
  3. Set appropriate timeout - Prevents hanging on slow servers
  4. Limit file size - Protects against DoS via large downloads

Exception Handling

Different exception types for different security scenarios:

Best Practices for User-Provided URLs

When accepting URLs from users:

Testing

Run the test suite:

Run tests with coverage:

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.


All versions of color-palette with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
php-http/discovery Version ^1.20
psr/http-client Version ^1.0
psr/http-factory Version ^1.1
psr/http-message Version ^2.0
psr/log Version ^1.1|^2.0|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package farzai/color-palette contains the following files

Loading the files please wait ...