Cant get it working
Im a front end dev here...
I cant seem to get this working at all. I just wanted to change a hex value to hsl and I'm going down a rabbit hole.
$color = new Color($stripe_color);
Why wont this work? It needs to be a string right?
@saltnpixels: First, you have to create a new Color object:
$myBlue = new Color("#336699");
The phpColors library has parsed the input value, which is a hex string, and stored it inside the color object. From this internal color representation you can now convert to a color format of your choice, here HSL:
print_r( $myBlue->getHsl() );
Notice the print_r, this is because getHsl() returns a PHP array. You can now pass that array or its individual values to another function/library that expects a HSL color, or output it, render it to a file, etc.
A hex string is just a representation of color, in this case RGB color values. How the computer/library stores and handles it internally, e.g. in what memory address, endianness, etc, should not be a concern here. This library should also work with hex strings that lack the # prefix btw.
... yes I understand this, but I didn’t pass a hex string. I passed a variable holding a hex string called $stripe_color.
It did work whe I passed a random hex string but for us I guess that’s not very useful... the color is coming from the database and has been stored in a variable.
@saltnpixels: You have to inspect the contents of that variable, either using a PHP debugger (which we all use far rarer than we should) or by using a PHP method:
var_dump($stripe_color);
Is the variable content actually a string? Are there any whitespaces (which could arguably be trimmed by this color library), encoding issues?
It’s a hex string and it has no spaces. The return value is #252525.
@saltnpixels: The RGB values for that particular hex string "#252525" are "37, 37, 37", correct?
....I have no idea. That’s why I’m using the plugin 😬
My goal is to take in a hex and check if the color is light or dark.
@saltnpixels: http://mexitek.github.io/phpColors/
Use the isLight or isDark methods, they accept a hex string as input.