mexitek / phpColors

A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.
http://mexitek.github.com/phpColors/
MIT License
486 stars 53 forks source link

Error converting from HSL to HEX - hslToHex() #39

Closed carmenates09 closed 2 years ago

carmenates09 commented 6 years ago

I'm trying to convert a HSL to HEX:

var_dump(Color::hslToHex( array( 'H' => 50, 'S' => 60, 'L' => 70) )); or var_dump(Color::hslToHex( array( 'H' => 50, 'S' => '60%', 'L' => '70%' ) ));

Result:

string(38) "fffffffffff029e6fffffffffff5888210618e"

Any advise? Jose Carlos Ramos Carmenates

mexitek commented 6 years ago

Saturation and Lighting should be a deecimal. In your case: var_dump(Color::hslToHex( array( 'H' => 50, 'S' => '.6', 'L' => '.7' ) ));

Ref: http://mexitek.github.io/phpColors/

On Mon, Feb 5, 2018 at 3:23 PM, Jose Carlos Ramos Carmenates < notifications@github.com> wrote:

I'm trying to convert a HSL to HEX:

var_dump(Color::hslToHex( array( 'H' => 50, 'S' => 60, 'L' => 70) )); or var_dump(Color::hslToHex( array( 'H' => 50, 'S' => '60%', 'L' => '70%' ) ));

Result:

string(38) "fffffffffff029e6fffffffffff5888210618e"

Any advise? Jose Carlos Ramos Carmenates

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mexitek/phpColors/issues/39, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfeekZdQV82dor6Yu5gVDMn_rpl6jqpks5tR42NgaJpZM4R6Qdr .

-- Arlo Carreon http://arlocarreon.com Web Developer

peter279k commented 4 years ago

In the Color::hslToHex method, the first argument is decimal string and it's the percent value.

The second and third arguments are the floating number string and they indicate the percent value.

The sample code snippets are as follows and it should make your code readability:

use Mexitek\PHPColors\Color;

Color::hslToHex(array( 'H' => 50, 'S' => '0.6', 'L' => '0.7' )); // "e0d185"