Skip to content
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

Closed
StringKe opened this issue May 19, 2020 · 3 comments
Closed

support convert hsl hsv cmyk? #32

StringKe opened this issue May 19, 2020 · 3 comments

Comments

@StringKe
Copy link

No description provided.

@sebastiandedeyne
Copy link
Member

HSL support has been added in #33 :)

@sebastiandedeyne
Copy link
Member

For other color systems: PR's welcome!

@StringKe
Copy link
Author

StringKe commented Jul 9, 2020

Hex: #530005ff not support
ff = round(hexdec(substr($hex, 6, 2)) / 255, 2)

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
Projects
None yet
Development

No branches or pull requests

2 participants