Convert hexadecimal color to RGB
@param string $color
@return stdClass Object
184515
private static function rgb($color) {

		return (object) [

			'r' => intval(hexdec(substr($color, 0, 2))),
			'g' => intval(hexdec(substr($color, 2, 2))),
			'b' => intval(hexdec(substr($color, 4, 2)))
		];
	}
985797
protected static function resolveColor($color, $mode = 'hex')
    {
        switch ($mode) {
            case 'hex':
                $red = sprintf('%02x', $color[0]);
                $green = sprintf('%02x', $color[1]);
                $blue = sprintf('%02x', $color[2]);
                $color = '#' . $red . $green . $blue;
                break;
            case 'rgb':
                $colorStr = self::hasAlpha($color) ? 'rgba(' : 'rgb(';

                $colorStr .= '' . $color[0] . ',' . $color[1] . ',' . $color[2];

                $colorStr .= self::hasAlpha($color) ? ',' . number_format($color[3], 2, '.', ',') . ')' : ')';
                $color = $colorStr;
                break;
            default:
                $color = '';
        }

        return $color;
    }
1229350
public function getArgbHexString(Color $color)
    {
        $alpha = dechex(255 * $color->alpha);
        return '#' . $alpha . $color->hex;
    }
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))
        );
    }
71568
public static function getInvertedColor($color)
    {
        // Prepare the color for later usage
        $color = trim($color);
        $withHash = Regex::startsWith($color, '#');

        /*
         * Verify and get valid value of color.
         * An exception will be thrown if the value is not a color.
         */
        $validColor = Regex::getValidColorHexValue($color);

        // Grab color's components
        $red = hexdec(substr($validColor, 0, 2));
        $green = hexdec(substr($validColor, 2, 2));
        $blue = hexdec(substr($validColor, 4, 2));

        // Calculate inverted color's components
        $redInverted = self::getValidColorComponent(255 - $red);
        $greenInverted = self::getValidColorComponent(255 - $green);
        $blueInverted = self::getValidColorComponent(255 - $blue);

        // Voila, here is the inverted color
        $invertedColor = sprintf('%s%s%s', $redInverted, $greenInverted, $blueInverted);

        if ($withHash) {
            return sprintf('#%s', $invertedColor);
        }

        return $invertedColor;
    }
623734
private function _get_hue( $hex ) {
		$red   = hexdec( substr( $hex, 0, 2 ) );
		$green = hexdec( substr( $hex, 2, 2 ) );
		$blue  = hexdec( substr( $hex, 4, 2 ) );
		$max_rgb = max( $red, $green, $blue );
		$min_rgb = min( $red, $green, $blue );

		if ( $red === $green && $red === $blue ) {
			return 0;
		}

		$diff_max_min_rgb = $max_rgb - $min_rgb;

		if ( $red === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $green - $blue ) / $diff_max_min_rgb : 0 );
		} elseif ( $green === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $blue - $red ) / $diff_max_min_rgb : 0 ) + 120;
		} elseif ( $blue === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $red - $green ) / $diff_max_min_rgb : 0 ) + 240;
		}

		if ( 0 > $hue ) {
			$hue += 360;
		}

		return $hue;
	}
1047575
static function htmltorgbPchart($color)
    {
        if (is_array($color)) {
            return $color;
        }

        if ($color[0] == '#') {
            $color = substr($color, 1);
        }

        if (strlen($color) == 6) {
            list($r, $g, $b) = array($color[0] . $color[1],
                $color[2] . $color[3],
                $color[4] . $color[5]);
        } elseif (strlen($color) == 3) {
            list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
        } else {
            return array("R" => 0, "G" => 0, "B" => 0);
        }

        $r = hexdec($r);
        $g = hexdec($g);
        $b = hexdec($b);

        return array("R" => $r, "G" => $g, "B" => $b);
    }
277884
public static function hex2rgb($color)
    {
        $color = str_replace('#', '', $color);

        $hex = strlen($color) == 3
            ? [$color[0].$color[0], $color[1].$color[1], $color[2].$color[2]]
            : [$color[0].$color[1], $color[2].$color[3], $color[4].$color[5]];

        list($r, $g, $b) = $hex;

        return sprintf(
            'rgb(%s, %s, %s)',
            hexdec($r),
            hexdec($g),
            hexdec($b)
        );
    }
1184194
private function getColorID($color)
    {
        list ($r, $g, $b) = explode(
            ' ',
            implode(' ', str_split(strtoupper(3 === strlen($color) ? $color . $color : $color), 2))
        );

        return imagecolorallocate($this->resource, hexdec($r), hexdec($g), hexdec($b));
    }
518850
public function fg($color)
    {
        Assert::nullOrOneOf($color, self::$colors, 'The color must be null or one of the Style::* color constants. Got: "%s"');

        $this->fgColor = $color;

        return $this;
    }
147927
protected function toRGB($color) {
if ($color[0] == 'color') return $color;

$H = $color[1] / 360;
$S = $color[2] / 100;
$L = $color[3] / 100;

if ($S == 0) {
$r = $g = $b = $L;
} else {
$temp2 = $L < 0.5 ?
$L*(1.0 + $S) :
$L + $S - $L * $S;

$temp1 = 2.0 * $L - $temp2;

$r = $this->toRGB_helper($H + 1/3, $temp1, $temp2);
$g = $this->toRGB_helper($H, $temp1, $temp2);
$b = $this->toRGB_helper($H - 1/3, $temp1, $temp2);
}

// $out = array('color', round($r*255), round($g*255), round($b*255));
$out = array('color', $r*255, $g*255, $b*255);
if (count($color) > 4) $out[] = $color[4]; // copy alpha
return $out;
}
1242093
private static function convertHexColorToRtf($color)
    {
        if (strlen($color) == 6) {
            $red    = hexdec(substr($color, 0, 2));
            $green  = hexdec(substr($color, 2, 2));
            $blue   = hexdec(substr($color, 4, 2));

            return '\red' . $red . '\green' . $green . '\blue' . $blue;
        }

        throw new PHPRtfLite_Exception('Color must be a hex number of length 3 or 6 digits! You gave me: #' . $color);
    }
480837
public function color($color)
    {
        if ($color instanceof Collection) {
            $color = $color->toArray();
        }

        return $this->options([
            'color' => $color,
        ]);
    }
295597
function rgb($color) {
		if (is_string($color))
			$color=hexdec($color);
		$hex=str_pad($hex=dechex($color),$color<4096?3:6,'0',STR_PAD_LEFT);
		if (($len=strlen($hex))>6)
			user_error(sprintf(self::E_Color,'0x'.$hex),E_USER_ERROR);
		$color=str_split($hex,$len/3);
		foreach ($color as &$hue) {
			$hue=hexdec(str_repeat($hue,6/$len));
			unset($hue);
		}
		return $color;
	}
98331
public function setDefaultBackgroundColor($color)
    {
        $this->log("Setting default background color to '$color'.");

        if (!(strlen($color) == 6 || strlen($color) == 8)) {
            throw new Exception(
                "Background color needs a hex value of 6 or 8
                digits. 000000-FFFFFF or 00000000-FFFFFF7F.
                Current value was: '$color'."
            );
        }

        $red    = hexdec(substr($color, 0, 2));
        $green  = hexdec(substr($color, 2, 2));
        $blue   = hexdec(substr($color, 4, 2));

        $alpha = (strlen($color) == 8)
            ? hexdec(substr($color, 6, 2))
            : null;

        if (($red < 0 || $red > 255)
            || ($green < 0 || $green > 255)
            || ($blue < 0 || $blue > 255)
            || ($alpha < 0 || $alpha > 127)
        ) {
            throw new Exception(
                "Background color out of range. Red, green blue
                should be 00-FF and alpha should be 00-7F.
                Current value was: '$color'."
            );
        }

        $this->bgColor = strtolower($color);
        $this->bgColorDefault = array(
            'red'   => $red,
            'green' => $green,
            'blue'  => $blue,
            'alpha' => $alpha
        );

        return $this;
    }
84264
public function color($color)
    {
        if ($color !== null) {
            Checkers::checkColor($color, null);
        }
        $this->color = $color;
        return $this;
    }
1235411
protected function getColorMapOrAsHex(string $color)
    {
        return isset($this->colorMap[$color]) ? $this->colorMap[$color] : $color;
    }