artack / color
Color helper library for converting between RGB, CMYK, HSV, HST and HEX and create interpolation.
Installs: 22 618
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.4|^8.0
- clue/graph: ^0.9.0
- graphp/algorithms: ^0.8.1
- webmozart/assert: ^1.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.9
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-21 14:25:58 UTC
README
color conversions and transitions (e.g. interpolation).
Developed by ARTACK WebLab GmbH in Zurich, Switzerland.
Features
- Provides class representation for RGB, CMYK, HSV, HSL and HEX.
- Provides conversion between all class representation
- Provides transitions between colors (e.g. interpolation)
- Provides clear exceptions to be able to handle library exceptions
- Compatible with PHP >= 7 and >= 8.
Installation
You can install this color library through Composer:
$ composer require artack/color
Usage
Creating a RGB class representation:
$RGB = new RGB(0, 255, 0); echo $RGB->getGreen(); // 255
Translate RGR class representation to HSV:
$converter = Factory::createConverter(); $RGB = new RGB(0, 255, 0); $HSV = $converter->convert($RGB, HSV::class);
Get an interpolation color between two colors with the value (and max) given:
$transition = Factory::createTransition(); $RGBRed = new RGB(255, 0, 0); // red $RGBGreen = new RGB(0, 255, 0); // green $RGBInterpolated = $transition->interpolate(RGB::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow // Interpolation will give better results when using HSV Transition. Colors get converted automatically if needed. $HSVInterpolated = $transition->interpolate(HSV::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow