https://github.com/ramazancetinkaya/color-code-converter
A modern PHP library for converting color codes between RGB, HEX, and HSL. Built for readability, scalability, and production use, it’s your go-to solution for color manipulation.
https://github.com/ramazancetinkaya/color-code-converter
color-code-converter color-codes hex hsl php php-library rgb
Last synced: 2 months ago
JSON representation
A modern PHP library for converting color codes between RGB, HEX, and HSL. Built for readability, scalability, and production use, it’s your go-to solution for color manipulation.
- Host: GitHub
- URL: https://github.com/ramazancetinkaya/color-code-converter
- Owner: ramazancetinkaya
- License: mit
- Created: 2024-12-30T15:32:19.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-30T18:39:26.000Z (6 months ago)
- Last Synced: 2025-03-27T00:54:56.406Z (3 months ago)
- Topics: color-code-converter, color-codes, hex, hsl, php, php-library, rgb
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Color Code Converter

[](https://packagist.org/packages/ramazancetinkaya/color-code-converter)


[](https://github.com/ramazancetinkaya/color-code-converter/stargazers)
[](https://github.com/ramazancetinkaya/color-code-converter/issues)A **powerful, modern, and extensible PHP library** for converting color codes between various color spaces, such as **RGB**, **HEX**, and **HSL**. Designed with a focus on readability, scalability, and production readiness, this library is the ultimate solution for color manipulation.
Report a Bug
·
New Pull Request### ⭐ Show Your Support
If you like this project, give it a ⭐ and share it with your network!
---
## Features
✨ **Versatile Color Conversions**
Effortlessly convert color codes between popular formats:
- 🔄 **RGB ↔ HEX**
- 🔄 **RGB ↔ HSL**
- 🔄 **HEX ↔ HSL**⚡ **Modern PHP Standards**
Built with PHP 8+ features for high performance and future-proof compatibility:
- 🏷️ Strict typing (`strict_types=1`)
- 🛠️ Fully typed methods🛡️ **Robust Error Handling**
- 🔍 Input validation with detailed exceptions
- 🛑 Catch invalid formats before they propagate🧩 **Extensible Architecture**
- 📦 Add support for additional color spaces (e.g., CMYK, LAB) with ease
- 🏗️ Modular design for seamless integration📘 **Comprehensive Documentation**
- 📝 Fully documented methods with standardized PHPDoc comments
- 📚 Clear usage examples🌐 **Production-Ready**
- 🔒 Secure and reliable for real-world applications
- ⚙️ Optimized for maintainability and scalability## Installation
### Using Composer
You can install the `ColorCode` library using [Composer](https://getcomposer.org/). Run the following command in your terminal:
```bash
composer require ramazancetinkaya/color-code-converter
```### Manual Installation
Alternatively, download the source code and include it in your project manually.
1. Clone the repository:
```bash
git clone https://github.com/ramazancetinkaya/color-code-converter.git
```
2. Include the library in your project:
```php
require 'path/to/ColorConverter.php';
```
## UsageHere's how you can use the `ColorConverter` class:
```php
hexToRgb('#FF5733'); // [255, 87, 51]# echo '
' . print_r($rgb, true) . '';// Convert RGB to HEX
$hex = $converter->rgbToHex([255, 87, 51]); // "#FF5733"# echo $hex;
// Convert RGB to HSL
$hsl = $converter->rgbToHsl([255, 87, 51]); // [10.59, 100, 60]# echo '
' . print_r($hsl, true) . '';// Convert HSL to RGB
$rgb2 = $converter->hslToRgb([14.29, 100, 60]); // [255, 100, 51]# echo '
' . print_r($rgb2, true) . '';// Convert HEX to HSL
$hsl2 = $converter->hexToHsl('#FF5733'); // [10.59, 100, 60]# echo '
' . print_r($hsl2, true) . '';// Convert HSL to HEX
$hex2 = $converter->hslToHex([14.29, 100, 60]); // "#FF5733"# echo $hex2;
```## API Documentation
### `hexToRgb(string $hexColor): array`
Converts a HEX color string to its RGB representation.
- **Parameters**:
- `$hexColor` *(string)*: The HEX color string (e.g., `"#FF5733"`, `"FF5733"`).
- **Returns**:
- *(array)*: An RGB array `[R, G, B]` with values between `0-255`.---
### `rgbToHex(array $rgbArray): string`
Converts an RGB array to a HEX color string.
- **Parameters**:
- `$rgbArray` *(array)*: An array `[R, G, B]` with values between `0-255`.
- **Returns**:
- *(string)*: The HEX color string (e.g., `"#FF5733"`).---
### `rgbToHsl(array $rgbArray): array`
Converts an RGB array to its HSL representation.
- **Parameters**:
- `$rgbArray` *(array)*: An array `[R, G, B]` with values between `0-255`.
- **Returns**:
- *(array)*: An HSL array `[H, S, L]` where:
- `H` (Hue): `0-360`
- `S` (Saturation): `0-100` (%)
- `L` (Lightness): `0-100` (%)---
### `hslToRgb(array $hslArray): array`
Converts an HSL array to its RGB representation.
- **Parameters**:
- `$hslArray` *(array)*: An array `[H, S, L]` where:
- `H` (Hue): `0-360`
- `S` (Saturation): `0-100` (%)
- `L` (Lightness): `0-100` (%)
- **Returns**:
- *(array)*: An RGB array `[R, G, B]` with values between `0-255`.## Project Structure
```plaintext
src/
├── ColorConverter.php
composer.json
README.md
LICENSE
```## Security
This library is designed with security in mind. Input validation and error handling are implemented to prevent misuse. For vulnerabilities, please [open an issue](https://github.com/ramazancetinkaya/color-code-converter/issues).
## Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
## Authors
This project is maintained with ❤️ by:
- **[Ramazan Çetinkaya](https://github.com/ramazancetinkaya)** - *Developer*
- GitHub: [@ramazancetinkaya](https://github.com/ramazancetinkaya)## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.