-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support convert hsl hsv cmyk? #32
Labels
Comments
HSL support has been added in #33 :) |
For other color systems: PR's welcome! |
Hex: #530005ff not support my convert alpha hex code: $color = "#530005ff";
if (strpos($color, '#') !== false) {
$hex = str_replace('#', '', $color);
$length = strlen($hex);
$r = 255;
$g = 255;
$b = 255;
$a = 1;
if ($length === 3) {
$r = hexdec(substr($color, 0, 2));
$g = hexdec(substr($color, 2, 2));
$b = hexdec(substr($color, 4, 2));
} else if ($length >= 6) {
$r = hexdec($length >= 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$g = hexdec($length >= 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
$b = hexdec($length >= 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
}
if ($length == 8) {
$a = round(hexdec(substr($hex, 6, 2)) / 255, 2);
}
return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $a . ')';
} Hope to help your |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: