carloscabo / husl
HSLuv / RGB / hex 颜色转换库
2.0.0
2017-02-21 02:18 UTC
Requires (Dev)
- phpunit/phpunit: 5.6.1
This package is not auto-updated.
Last update: 2024-09-18 20:27:56 UTC
README
从 Python / JS 的 HSLuv (修订版 4) 转移到 PHP (5.6+) 的端口。
运行测试
composer install
./vendor/bin/phpunit
用法
composer require "hsluv/hsluv"
从 RGB / hex 转换到 HSLuv
// 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 ) );
返回一个包含 浮点数 的 HSLuv 数组 (H, S, L)。
从 HSLuv 转换到 RGB / hex
参数是浮点数 H, S, L 元素或数组。
// 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 ) )
作者
- 由 Carlos Cabo 转移 (carloscabo)
- 通过测试和打包提供支持 (tasugo)
- 原始 HSLuv 作者:Alexei Boronine (boronine)