renfordt / colors
A php library to convert and modify colors.
Requires
- php: ^8.1
- renfordt/clamp: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-12-14 21:24:21 UTC
README
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.
Installation
You can install this package using Composer. Run the following command:
composer require renfordt/colors
Requirements
- PHP 8.1 or higher
- Composer
Usage
Initializing Colors
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]);
Converting Colors
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();
Available Methods
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()
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This package is open-sourced software licensed under the MIT license.