jalaljaberi/negarity-color

Negarity Color — a modern, extensible color manipulation library for PHP.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/jalaljaberi/negarity-color

dev-main 2026-01-24 14:52 UTC

This package is not auto-updated.

Last update: 2026-02-10 19:46:05 UTC


README

Negarity Color is a modern, extensible color manipulation library for PHP 8.3+.

Installation

composer require jalaljaberi/negarity-color

Basic Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Negarity\Color\Color;
use Negarity\Color\Registry\ColorSpaceRegistry;

// Register built-in color spaces (required before use)
ColorSpaceRegistry::registerBuiltIn();

// Create colors
$primary = Color::rgb(255, 100, 50);
$secondary = Color::hex('#3498db');

// Convert between color spaces
$hsl = $primary->toHSL();
$cmyk = $primary->toCMYK();

// Read channels
$r = $primary->getR();        // 255
$space = $primary->getColorSpaceName(); // "rgb"

// Modify (immutable by default)
$lighter = $primary->with(['g' => 150]);

echo $primary->toHex();   // "#FF6432"
echo (string) $hsl;       // "hsl(...)"

Configuration (Optional)

Named colors

Register a named-color registry once, then use Color::{name}():

use Negarity\Color\Color;
use Negarity\Color\Registry\VGANamedColors;

Color::addRegistry(new VGANamedColors());

$red = Color::red();
$navyHsl = Color::navy(\Negarity\Color\ColorSpace\HSL::class);

Color Spaces

Color spaces must be registered before use. Register all built-in color spaces:

use Negarity\Color\Registry\ColorSpaceRegistry;

ColorSpaceRegistry::registerBuiltIn();

Filters

Filters must be registered before they are available as methods on Color objects:

use Negarity\Color\Color;
use Negarity\Color\Filter\FilterRegistry;
use Negarity\Color\Filter\Parameterized\BrightnessFilter;
use Negarity\Color\Filter\Unary\InvertFilter;

FilterRegistry::register(new BrightnessFilter());
FilterRegistry::register(new InvertFilter());

$color = Color::rgb(255, 100, 50)
    ->brightness(20)
    ->invert();

Documentation

Getting started

References

  • Martin Krzywinski color table - A comprehensive list of 9,284 named colors with conversions across multiple color spaces (RGB, HSV, XYZ, Lab, LCH, CMYK)

License

MIT