renfordt/colors
is a PHP package that provides several classes for handling different color types, including Hex, HSL, HSV, RAL, and RGB. These color types can be easily converted into each other using this package.
You can install this package using Composer. Run the following command:
composer require renfordt/colors
- PHP 8.1 or higher
- Composer
You can initialize colors in multiple formats using the create
method:
use Renfordt\Colors\HexColor;
use Renfordt\Colors\HSLColor;
use Renfordt\Colors\HSVColor;
use Renfordt\Colors\RALColor;
use Renfordt\Colors\RGBColor;
// HEX Color
$hexColor = HexColor::create('#ffffff');
// HSL Color
$hslColor = HSLColor::create([360, 100, 50]);
// HSV Color
$hsvColor = HSVColor::create([360, 100, 100]);
// RAL Color
$ralColor = RALColor::create('9010');
// RGB Color
$rgbColor = RGBColor::create([255, 255, 255]);
You can convert colors from one type to another easily:
// Convert Hex to RGB
$rgbColor = $hexColor->toRGB();
// Convert RGB to HSL
$hslColor = $rgbColor->toHSL();
// Convert HSL to HSV
$hsvColor = $hslColor->toHSV();
// Convert HSV to RAL (this might require a predefined mapping)
$ralColor = $hsvColor->toRAL();
Each color class offers a set of methods to manipulate and retrieve color values.
-
Hex
toRGB()
toHSL()
toHSV()
toRAL()
-
HSL
toHex()
toRGB()
toHSV()
toRAL()
-
HSV
toHex()
toRGB()
toHSL()
toRAL()
-
RAL
toHex()
toRGB()
toHSL()
toHSV()
-
RGB
toHex()
toHSL()
toHSV()
toRAL()
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This package is open-sourced software licensed under the MIT license.