Jyxo\Color::initFromHex PHP Method

initFromHex() private method

Sets color components using a hexadecimal RRGGBB string.
private initFromHex ( string $hex ) : self
$hex string Color definition
return self
    private function initFromHex(string $hex) : self
    {
        // Trim the hashmark if present
        $hex = ltrim($hex, '#');
        if (strlen($hex) == 3) {
            // RGB format support
            $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
        }
        if (!preg_match('~[a-f0-9]{6}~i', $hex)) {
            // Invalid color definition
            throw new \InvalidArgumentException(sprintf('"%s" in not a valid hexadecimal color definition', $hex));
        }
        $this->initFromInt(hexdec($hex));
        return $this;
    }