Grafika\Color::hexToRgb PHP Method

hexToRgb() public method

Convert hex string to RGB
public hexToRgb ( string $hex ) : array
$hex string Hex string. Possible values: #ffffff, #fff, fff
return array Contains (RGB) values red, green and blue
    public function hexToRgb($hex)
    {
        $hex = ltrim($hex, '#');
        // Remove #
        if (strlen($hex) == 3) {
            $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
            $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
            $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
        } else {
            $r = hexdec(substr($hex, 0, 2));
            $g = hexdec(substr($hex, 2, 2));
            $b = hexdec(substr($hex, 4, 2));
        }
        return array($r, $g, $b);
        // Returns an array with the rgb values
    }