Converts any valid SVG color string into an array of RGBA components.

All of the components are ints 0-255.

@param string $color The color string to convert, as specified in SVG.

@return int[] The color converted to RGBA components.
491486
public static function parse($color)
    {
        $lookupResult = ColorLookup::get($color);
        if (isset($lookupResult)) {
            return $lookupResult;
        }

        // pass on to dedicated functions depending on notation
        if (preg_match('/^#([0-9A-F]+)$/i', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHexComponents($matches[1]);
        } elseif (preg_match('/^rgba?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseRGBAComponents($matches[1]);
        } elseif (preg_match('/^hsla?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHSLAComponents($matches[1]);
        }

        // any illegal component invalidates all components
        if (!isset($r) || !isset($g) || !isset($b) || !isset($a)) {
            return array(0, 0, 0, 0);
        }

        return self::clamp($r, $g, $b, $a);
    }
245014
public static function ToDecArray ($rgb) {
		return (($hex_array = static::ToHexStringArray($rgb)) !== false) ? [hexdec($hex_array[0]), hexdec($hex_array[1]), hexdec($hex_array[2])] : false;
	}
1211014
public static function parseHex($color)
    {
        if (!preg_match('/^#[A-Fa-f0-9]{6}$/', $color)) {
            throw new WrongColorFormatException($color);
        }

        return new Color(
            hexdec(substr($color, 1, 2)),
            hexdec(substr($color, 3, 2)),
            hexdec(substr($color, 5, 2))
        );
    }
152600
protected function renderItem($color)
    {
        return Html::tag('div', (
            Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'circle-clipper left'])
            . Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'gap-patch'])
            . Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'circle-clipper right'])
        ), ['class' => 'spinner-layer spinner-' . $color]);
    }
1118462
public static function fromHex(string $color): Color
    {
        if (!Validator::isValidHex($color)) {
            throw new InvalidColorException('Invalid hex value');
        }

        return new self(...array_values(self::hexToRgb($color)));
    }
345073
public function getColorWithRGB($color) {
		if (func_num_args() == 1 && is_int($color)) {
			return $color;
		}
		if (is_string($color)) {
			$color = self::transformRGB($color);
		} elseif(func_num_args() == 3) {
			$color = func_get_args();
		}
		return imagecolorallocate($this->image, $color[0], $color[1], $color[2]);
	}
90104
public static function getColorCode($color, $options = array())
    {
        $code = (int) $color;
        if (is_string($color)) {
            $options = array_merge(explode('+', strtolower($color)), $options);
            $color = array_shift($options);
            if (!isset(self::$colors[$color])) {
                throw new ConsoleException("Unknown color '$color'");
            }
            $code = self::$colors[$color];
        }
        foreach ($options as $opt) {
            $opt = strtolower($opt);
            if (!isset(self::$options[$opt])) {
                throw new ConsoleException("Unknown option '$color'");
            }
            $code = $code | self::$options[$opt];
        }
        return $code;
    }
528490
protected function hex2rgb($hexcolor) 
    {
        preg_match("/^#{0,1}([0-9a-f]{1,6})$/i", $hexcolor, $match);

        if (!isset($match[1])) {
            return [];
        }

        $color = $match[1];

        #91d04d
        if (6 == strlen($color)) {
            list($r, $g, $b) = [
                $color[0] . $color[1],
                $color[2] . $color[3],
                $color[4] . $color[5]
            ];
        } else if (3 == strlen($color)) {
            #aaa
            list($r, $g, $b) = [
                $color[0] . $color[0],
                $color[1] . $color[1],
                $color[2] . $color[2]
            ];
        } else if (2 == strlen($color)) {
            #bb
            list($r, $g, $b) = [
                $color[0] . $color[1],
                $color[0] . $color[1],
                $color[0] . $color[1]
            ];
        } else if (1 == strlen($color)) {
            #c
            list($r, $g, $b) = [
                $color . $color,
                $color . $color,
                $color . $color
            ];
        } else {
            return [];
        }

        return [
            'r' => hexdec($r),
            'g' => hexdec($g),
            'b' => hexdec($b),
        ];
    }
1139131
protected function initialize($color)
    {
        return list($this->hue, $this->saturation, $this->lightness) = explode(',', $color);
    }
871060
protected static function normalizeColorString($origColor): array
    {
        $color = trim($origColor, '#');
        $color = trim($color);

        if (strlen($color) === 6) {
            list($red, $green, $blue) = [
                $color[0] . $color[1],
                $color[2] . $color[3],
                $color[4] . $color[5],
            ];
        } elseif (strlen($color) === 3) {
            list($red, $green, $blue) = [
                $color[0] . $color[0],
                $color[1] . $color[1],
                $color[2] . $color[2],
            ];
        } else {
            throw new Exception('Undefined color format (string): ' . $origColor); // @codeCoverageIgnore
        }

        $red = hexdec($red);
        $green = hexdec($green);
        $blue = hexdec($blue);

        return [$red, $green, $blue, 0];
    }
1367339
protected function fixPrecision($color)
    {
        if (strpos($color, ',') !== false) {
            $parts = explode(',', $color);
            $parts[3] = strpos($parts[3], '.') === false ? $parts[3] . '.0' : $parts[3];
            $color = implode(',', $parts);
        }
        return $color;
    }
1350941
private function convertColor($color)
    {
        if (is_array($color)) {
            return $color;
        }

        if (preg_match('/^#?([a-z\d])([a-z\d])([a-z\d])$/i', $color, $matches)) {
            $color = $matches[1].$matches[1];
            $color .= $matches[2].$matches[2];
            $color .= $matches[3].$matches[3];
        }

        preg_match('/#?([a-z\d]{2})([a-z\d]{2})([a-z\d]{2})$/i', $color, $matches);

        return array_map(function ($value) {
            return hexdec($value);
        }, array_slice($matches, 1, 3));
    }
523594
protected function isValidColor($color)
	{
		$regexp = '\(([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\)';
		
		return preg_grep("/{$color}/i", $this->getColors()) || preg_match('/^#(\d|a|b|c|d|e|f){3}$/i', $color)
			|| preg_match('/^#(\d|a|b|c|d|e|f){6}$/i', $color) || preg_match('/^(rgb)'.$regexp.'$/i', $color)
			|| preg_match('/^(rgba)'.$regexp.'?\W+([01](\.\d+)?)\)$/i', $color);
	}
12521
public function setColor($color)
    {
        $allowed_values = array('#ffffff', '#ffff01', '#ff6600', '#fe0000', '#9a0000', '#660066', '#0000fe', '#0099ff', '#01ffff', '#00ff33', '#349800', '#006634', '#666666', '#999999', '#e6e6e6', '#ffffcd', '#99ffff', '#ccff9a');
        if (!is_null($color) && (!in_array($color, $allowed_values))) {
            throw new \InvalidArgumentException("Invalid value for 'color', must be one of '#ffffff', '#ffff01', '#ff6600', '#fe0000', '#9a0000', '#660066', '#0000fe', '#0099ff', '#01ffff', '#00ff33', '#349800', '#006634', '#666666', '#999999', '#e6e6e6', '#ffffcd', '#99ffff', '#ccff9a'");
        }
        $this->container['color'] = $color;

        return $this;
    }
1045444
public function validateColor($color)
    {
        $request = new Request('GET', 'color');
        $response = $this->sendRequest($request, [
            'query' => [
                'string' => $color,
            ]
        ]);

        return $response->getBody();
    }
342383
public static function rgb2hsv( $rgb )
	{
#		return self::rgb2hsv_2( $rgb );
		list( $r, $g, $b ) = $rgb;
		$v	= max( $r, $g, $b );
		$t	= min( $r, $g, $b );
		$s	= ( $v == 0 ) ? 0 : ( $v - $t ) / $v;
		if( $s == 0 )
			$h	= 0;
		else
		{
			$a	= $v - $t;
			$cr	= ( $v - $r ) / $a;
			$cg	= ( $v - $g ) / $a;
			$cb	= ( $v - $b ) / $a;
			$h	= ( $r == $v ) ? $cb - $cg : ( ( $g == $v ) ? 2 + $cr - $cb : ( ( $b == $v ) ? $h = 4 + $cg - $cr : 0 ) );
			$h	= 60 * $h;
			$h	= ( $h < 0 ) ? $h + 360 : $h;
		}
		return array( round( $h ), round( $s * 100 ), round( $v / 2.55 ) );
	}
238237
public function getColorIndex($color)
    {
        $color = self::getColorAsFullHexCode($color);
        $index = array_search($color, $this->_colors);
        return $index !== false ? $index + 1 : false;
    }