spatie / color

A little library to deal with color conversions

Home Page:https://spatie.be/opensource/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consolidate color spaces to a single class

sebastiandedeyne opened this issue · comments

Brain dump incoming

Consolidate all color spaces in a single color class that holds the color information.

rgb, rgba and hex all use the same color space. hls uses a different one so would need to be stored differently or we'd lose data.

API sketch:

Color::fromString('rgb(255, 0, 255)');

// Formats return diffrent objects depending on the  format
$color->rgb()->__toString();
$color->rgb()->red();
$color->hex()->red();

// $color->rgb()->toHls() should also be possible

// Changing color spaces requires an explicit conversion (different implementation of `Color`)
// For example, you can't get `red` from a `hls` color
$color->toHls()->hue();

Closing for now. Might come back later.