PHPackages                             janwalenda/spectra - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. janwalenda/spectra

ActiveLibrary

janwalenda/spectra
==================

A PHP 7.4+ library for color conversion between HEX, RGB(A), HSL(A) and the perceptually uniform OKLCH color space.

0178↑383.9%PHP

Since Nov 6Pushed 6mo agoCompare

[ Source](https://github.com/janwalenda/sprectra)[ Packagist](https://packagist.org/packages/janwalenda/spectra)[ RSS](/packages/janwalenda-spectra/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Spectra - PHP Color Space Converter
===================================

[](#spectra---php-color-space-converter)

Spectra is a PHP 7.4+ library for color space conversions between HEX, RGB(A), HSL(A), and the perceptually uniform OKLCH color space.

Installation
------------

[](#installation)

Install via Composer:

```
composer require janwalenda/spectra
```

Features
--------

[](#features)

- Convert between common web color formats:
    - HEX (`#RGB`, `#RRGGBB`, `#RRGGBBAA`)
    - RGB/RGBA (`rgb(r,g,b)`, `rgba(r,g,b,a)`)
    - HSL/HSLA (`hsl(h,s%,l%)`)
    - OKLCH (`oklch(l c h)`, `oklch(l c h / a%)`)
- Supports transparency (alpha channel)
- Perceptual uniformity through OKLCH
- Calculate contrast colors
- Parse color strings in various formats

Usage
-----

[](#usage)

### Basic Color Space Conversion

[](#basic-color-space-conversion)

```
use Janwalenda\Spectra\Converter;

$converter = new Converter();

// Convert HEX to OKLCH
$oklch = $converter->getDynamicOklchColor('#ff0000');
// Result: "oklch(0.6319 0.2789 29.2337)"

// Convert RGB to OKLCH
$oklch = $converter->getDynamicOklchColor('rgb(255, 0, 0)');

// Get contrasting color
$contrast = $converter->getDynamicContrastOklchColor('#ffffff');
// Returns black as OKLCH for white background
```

### Working with Color Objects

[](#working-with-color-objects)

```
use Janwalenda\Spectra\RGB;
use Janwalenda\Spectra\HSL;
use Janwalenda\Spectra\LCH;

// Create RGB color
$rgb = new RGB(255, 0, 0, 0.5);  // Red at 50% opacity

// Parse colors from strings
$rgb = RGB::parseFromString('rgba(255, 0, 0, 0.5)');
$hsl = HSL::parseFromString('hsl(0, 100%, 50%)');
$lch = LCH::parseFromString('oklch(50 20 180)');
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Composer for installation

License
-------

[](#license)

MIT License

Author
------

[](#author)

Jan Walenda ()

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance50

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/36485f85584988972b611d212dee869bca013f03c270635b661c07324e6482d6?d=identicon)[janwalenda](/maintainers/janwalenda)

---

Top Contributors

[![janwalenda](https://avatars.githubusercontent.com/u/51045811?v=4)](https://github.com/janwalenda "janwalenda (1 commits)")

### Embed Badge

![Health badge](/badges/janwalenda-spectra/health.svg)

```
[![Health](https://phpackages.com/badges/janwalenda-spectra/health.svg)](https://phpackages.com/packages/janwalenda-spectra)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
