Converts RGB to XYZ.
@access		public
@static
@param		array	rgb		RGB-Color as array
@return		array
506222
public static function rgb2xyz( $rgb )
	{
		list( $r, $g, $b ) = $rgb;
		$r	= $r / 255;
		$g	= $g / 255;
		$b	= $b / 255;
		$x	= 0.430574 * $r + 0.341550 * $g + 0.178325 * $b;
		$y	= 0.222015 * $r + 0.706655 * $g + 0.071330 * $b;
		$z	= 0.020183 * $r + 0.129553 * $g + 0.939180 * $b;
		return array( $x, $y, $z );
	}
1244377
public static function rgb2xyz($rgb)
    {
        // Inverse sRGB Companding
        $rgb = array_map(function ($n) {
            if ($n <= 0.04045) {
                return $n / 12.92;
            }
            return pow(($n + 0.055) / 1.055, 2.4);
        }, $rgb);

        // Linear RGB to XYZ
        return array(
            0.4124564 * $rgb[0] + 0.3575761 * $rgb[1] + 0.1804375 * $rgb[2],
            0.2126729 * $rgb[0] + 0.7151522 * $rgb[1] + 0.0721750 * $rgb[2],
            0.0193339 * $rgb[0] + 0.1191920 * $rgb[1] + 0.9503041 * $rgb[2]
        );
    }
60496
def hexa_to_rgb(color):
    """"""
    r = int(color[1:3], 16)
    g = int(color[3:5], 16)
    b = int(color[5:7], 16)
    if len(color) == 7:
        return r, g, b
    elif len(color) == 9:
        return r, g, b, int(color[7:9], 16)
    else:
        raise ValueError("Invalid hexadecimal notation.")
1301197
public function rgbXY($x, $y) {
        $color = $this->colorXY($x, $y);
        return array(($color >> 16) & 0xFF, ($color >> 8) & 0xFF, $color & 0xFF);
    }
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 ) );
	}
772582
function(rgb){
            var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
            var hex = (parts[1]<<16|parts[2]<<8|parts[3]).toString(16);
            return "#"+Array(6-hex.length).concat([hex]).toString().replace(/,/g, 0);
        }
647938
function adobe_rgb_to_xyz (r, g, b) {
	// matrix is from http://www.brucelindbloom.com/
	var x = r * 0.576700 + g * 0.185556 + b * 0.188212;
	var y = r * 0.297361 + g * 0.627355 + b * 0.0752847;
	var z = r * 0.0270328 + g * 0.0706879 + b * 0.991248;

	return {
		x: x, y: y, z: z
	};
}
582896
private static function readRGB($rgb)
    {
        // offset: 0; size 1; Red component
        $r = ord($rgb{0});

        // offset: 1; size: 1; Green component
        $g = ord($rgb{1});

        // offset: 2; size: 1; Blue component
        $b = ord($rgb{2});

        // HEX notation, e.g. 'FF00FC'
        $rgb = sprintf('%02X%02X%02X', $r, $g, $b);

        return array('rgb' => $rgb);
    }
1007677
private static function _readRGB($rgb)
	{
		// offset: 0; size 1; Red component
		$r = ord($rgb{0});

		// offset: 1; size: 1; Green component
		$g = ord($rgb{1});

		// offset: 2; size: 1; Blue component
		$b = ord($rgb{2});

		// HEX notation, e.g. 'FF00FC'
		$rgb = sprintf('%02X%02X%02X', $r, $g, $b);

		return array('rgb' => $rgb);
	}
334301
public static function colorToHex($color)
    {
        $colors = array(
            'maroon'    => '800000',
            'red'       => 'FF0000',
            'orange'    => 'FFA500',
            'yellow'    => 'FFFF00',
            'olive'     => '808000',
            'purple'    => '800080',
            'fuchsia'   => 'FF00FF',
            'white'     => 'FFFFFF',
            'lime'      => '00FF00',
            'green'     => '008000',
            'navy'      => '000080',
            'blue'      => '0000FF',
            'aqua'      => '00FFFF',
            'teal'      => '008080',
            'black'     => '000000',
            'silver'    => 'C0C0C0',
            'gray'      => '808080',
        );
        if (array_key_exists($color, $colors)) {
            return $colors[$color];
        }
        
        $color_pattern = '/rgb\((.*?)\)/';
        preg_match($color_pattern, $color, $matches);
        if (is_array($matches) && count($matches) > 0) {
            $rgb = explode(',', $matches[1]);
            if (is_array($rgb) && count($rgb) === 3) {
                return self::RGBToHex($rgb[0], $rgb[1], $rgb[2]);
            }
        }
        
        return $color;
    }
666069
public static function setColors(array $colors = array())
    {
        if (!empty($colors)) {
            static::$colors = $colors;
            return;
        }
        static::$colors = array(
            \Monolog\Logger::DEBUG     => 'purple',
            \Monolog\Logger::INFO      => 'cyan',
            \Monolog\Logger::NOTICE    => 'green',
            \Monolog\Logger::WARNING   => 'yellow',
            \Monolog\Logger::ERROR     => 'red',
            \Monolog\Logger::CRITICAL  => 'red',
            \Monolog\Logger::ALERT     => 'red',
            \Monolog\Logger::EMERGENCY => 'red',
        );
    }
51132
public function getAvgRgb(): array
    {
        $resource = imagescale($this->resource, 1, 1);

        $rgba = imagecolorsforindex($resource, imagecolorat($resource, 0, 0));

        imagedestroy($resource);

        return array_slice(array_values($rgba), 0, 3);
    }
98303
public static function ToHexStringArray ($rgb) {
		$rgb = trim($rgb, '#');
		if ($rgb === '' || ($range = strlen($rgb) / 3) > 2) {
			return false;
		}

		$hex_array = [substr($rgb, 0, $range), substr($rgb, 1 * $range, $range), substr($rgb, 2 * $range, $range)];
		if ($range === 1) {
			$hex_array[0] .= $hex_array[0];
			$hex_array[1] .= $hex_array[1];
			$hex_array[2] .= $hex_array[2];
		}

		return $hex_array;
	}
1307565
protected function formatColor($value)
		# Author:     Jarrod Oberto
		# Date:       09-05-11
		# Purpose:    Determine color method passed in and return color as RGB
		# Param in:   (mixed) $value: (array) Could be an array of RGB
		#               (str) Could be hex #ffffff or #fff, fff, ffffff
		# Param out:
		# Reference:
		# Notes:
		#
	{
		$rgbArray = array();

		// *** If it's an array it should be R, G, B
		if (is_array($value))
		{

			if (key($value) == 0 && count($value) == 3)
			{

				$rgbArray['r'] = $value[0];
				$rgbArray['g'] = $value[1];
				$rgbArray['b'] = $value[2];

			}
			else
			{
				$rgbArray = $value;
			}
		}
		else
		{
			if (fix_strtolower($value) == 'transparent')
			{

				$rgbArray = array(
					'r' => 255,
					'g' => 255,
					'b' => 255,
					'a' => 127
				);

			}
			else
			{

				// *** ...Else it should be hex. Let's make it RGB
				$rgbArray = $this->hex2dec($value);
			}
		}

		return $rgbArray;
	}
757641
function hex2dec($hex)
		# Purpose:  Convert #hex color to RGB
	{
		$color = str_replace('#', '', $hex);

		if (strlen($color) == 3)
		{
			$color = $color . $color;
		}

		$rgb = array(
			'r' => hexdec(substr($color, 0, 2)),
			'g' => hexdec(substr($color, 2, 2)),
			'b' => hexdec(substr($color, 4, 2)),
			'a' => 0
		);

		return $rgb;
	}
1211358
private static function createHexArray(array $vals)
    {
        foreach ($vals as $r) {
            foreach ($vals as $g) {
                foreach ($vals as $b) {
                    $colors[] = self::rgbToHex($r, $g, $b);
                }
            }
        }
        
        return $colors;
    }
456752
protected static function normalizeColorArray(array $origColor): array
    {
        $result = [];

        if (Arr::key('r', $origColor) && Arr::key('g', $origColor) && Arr::key('b', $origColor)) {
            $result = [
                self::color($origColor['r']),
                self::color($origColor['g']),
                self::color($origColor['b']),
                self::alpha(Arr::key('a', $origColor) ? $origColor['a'] : 0),
            ];
        } elseif (Arr::key(0, $origColor) && Arr::key(1, $origColor) && Arr::key(2, $origColor)) {
            $result = [
                self::color($origColor[0]),
                self::color($origColor[1]),
                self::color($origColor[2]),
                self::alpha(Arr::key(3, $origColor) ? $origColor[3] : 0),
            ];
        }

        return $result;
    }