https://github.com/hsluv/hsluv-php
PHP implementation of HSLuv (revision 4)
https://github.com/hsluv/hsluv-php
Last synced: about 1 year ago
JSON representation
PHP implementation of HSLuv (revision 4)
- Host: GitHub
- URL: https://github.com/hsluv/hsluv-php
- Owner: hsluv
- License: mit
- Created: 2016-10-06T17:29:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-01T14:20:59.000Z (over 1 year ago)
- Last Synced: 2025-03-26T04:51:11.624Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 1.48 MB
- Stars: 15
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HSLuv-php
[](https://github.com/hsluv/hsluv-php/actions/workflows/test.yml)
Port to PHP (5.6+) from Python / JS of [HSLuv](http://www.hsluv.org/) (revision 4).
To run the tests:
```
composer install
./vendor/bin/phpunit
```
# Usage
```
composer require "hsluv/hsluv"
```
# From RGB / hex to HSLuv
````php
// From hex upper / lowercase
$out = HSLuv::fromHex( '#fabada' );
$out = HSLuv::fromHex( '#FABADA' );
// From RGB (float) in 0.0 - 1.0 range
$out = HSLuv::fromRgb( 0.9803921568627451, 0.7294117647058823, 0.8549019607843137 );
$out = HSLuv::fromRgb( array( 0.9803921568627451, 0.7294117647058823, 0.8549019607843137 ) );
// From RGB (int) in 0 - 255 range
$out = HSLuv::fromRgbInt( 250, 186, 218 );
$out = HSLuv::fromRgbInt( 250.0, 186.0, 218.0 );
$out = HSLuv::fromRgbInt( array( 250, 186, 218 ) );
$out = HSLuv::fromRgbInt( array( 250.0, 186.0, 218.0 ) );
````
Returns HSLuv an array of **float** values ( H, S, L ).
# From HSLuv to RGB / hex
Parameters are float H, S, L componets or an array.
```php
// Rgb: returns array of (float) in 0.0 - 1.0 range
$out = HSLuv::toRgb( $h, $s, $l )
$out = HSLuv::toRgb( array( $h, $s, $l ) )
// Rgb: returns array if (int) in 0 - 255 range
$out = HSLuv::toRgbInt( $h, $s, $l )
$out = HSLuv::toRgbInt( array( $h, $s, $l ) )
// Hex: returns lowercase string including "#"
$out = HSLuv::toHex( $h, $s, $l )
$out = HSLuv::toRgb( array( $h, $s, $l ) )
```
# Authors
- Port by Carlos Cabo ([carloscabo](https://github.com/carloscabo))
- Support with tests and packaging ([tasugo](https://github.com/tasugo))
- Original HSLuv author: Alexei Boronine ([boronine](http://github.com/boronine))