转化成颜色
@param int|string|array $color
@return int|false
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]);
	}
1074940
public static function foreground($color)
    {
        list($red, $green, $blue) = str_split(substr($color, 1), 2);

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

        return ($red < 200 && $green < 100 && $blue < 200) ? self::WHITE : self::BLACK;
    }
736236
static function resolveColor($color) {
        if(\is_int($color)) {
            return $color;
        }
        
        if(!\is_array($color)) {
            return \hexdec(((string) $color));
        }
        
        if(\count($color) < 1) {
            throw new \InvalidArgumentException('Color "'.\var_export($color, true).'" is not resolvable');
        }
        
        return (($color[0] << 16) + (($color[1] ?? 0) << 8) + ($color[2] ?? 0));
    }
791399
public static function name($color) {

		if(false === is_string($color)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($color)), E_USER_ERROR);
		}

		if(1 !== preg_match('#^[0-9a-fA-F]{6,6}$#', $color)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be a 6 character hexadecimal string', __METHOD__), E_USER_ERROR);
		}

		$color 	= strtoupper($color);
		$rgb 	= static :: rgb($color);
		$r 		= $rgb -> r; 
		$g 		= $rgb -> g; 
		$b 		= $rgb -> b;
		$hsl 	= static :: hsl($color);
		$h 		= $hsl -> h; 
		$s 		= $hsl -> s; 
		$l 		= $hsl -> l;
		$ndf1 	= 0;
		$ndf2 	= 0; 
		$ndf 	= 0;
		$cl 	= -1;
		$df 	= -1;

		//Index all the colors
		if(null === static :: $list) {

			new ColorList();
			static :: index();
		}

		foreach(static :: $list as $hex => $color) {

			$ndf1 = pow($r - $color -> r, 2) + pow($g - $color -> g, 2) + pow($b - $color -> b, 2);
			$ndf2 = pow($h - $color -> h, 2) + pow($s - $color -> s, 2) + pow($l - $color -> l, 2);
			$ndf  = $ndf1 + $ndf2 * 2;

			if($df < 0 || $df > $ndf) {

				$df = $ndf;
				$cl = $hex;
			}
		}

		if(true === isset(static :: $list[$cl])) {
			return static :: $list[$cl];
		}

		return null;
	}
1053933
static public function color($color) {
		if (!is_array($color)) {
			$color = compact('color');
		}

		$color += array('color' => null, 'style' => null, 'background' => null);

		if ($color['color'] == 'reset') {
			return "\033[0m";
		}

		$colors = array();
		foreach (array('color', 'style', 'background') as $type) {
			$code = $color[$type];
			if (isset(self::$_colors[$type][$code])) {
				$colors[] = self::$_colors[$type][$code];
			}
		}

		if (empty($colors)) {
			$colors[] = 0;
		}

		return "\033[" . join(';', $colors) . "m";
	}
532085
static public function writeOutput($text, $color = '')
    {
        switch ($color) {
            case self::COLOR_WHITE:
                $out = "[0m";
                break;
            case self::COLOR_WHITE_BOLD:
                $out = "[1m";
                break;
            case self::COLOR_WHITE_DIM:
                $out = "[2m";
                break;
            case self::COLOR_RED:
                $out = "[0;31m";
                break;
            case self::COLOR_RED_BOLD:
                $out = "[1;31m";
                break;
            case self::COLOR_RED_DIM:
                $out = "[2;31m";
                break;
            case self::COLOR_GREEN:
                $out = "[0;32m";
                break;
            case self::COLOR_GREEN_BOLD:
                $out = "[1;32m";
                break;
            case self::COLOR_GREEN_DIM:
                $out = "[2;32m";
                break;
            case self::COLOR_YELLOW:
                $out = "[0;33m";
                break;
            case self::COLOR_YELLOW_BOLD:
                $out = "[1;33m";
                break;
            case self::COLOR_YELLOW_DIM:
                $out = "[2;33m";
                break;
            default:
                echo UString::newLine() . $text;

                return true;
        }

        echo UString::newLine() . chr(27) . $out . $text . chr(27) . "[0m";

        return true;
    }
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);
	}
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;
}
1235411
protected function getColorMapOrAsHex(string $color)
    {
        return isset($this->colorMap[$color]) ? $this->colorMap[$color] : $color;
    }
547853
public static function colorize($string, $color)
    {
        if (isset(self::$colors[$color])) {
            return "\033[" . self::$colors[$color] . 'm' . $string . "\033[0m";
        }

        return $string;
    }
20874
public function setFromRGBColor(RGBColor $color)
    {
        return $this->setRed($color->getRed())
                        ->setGreen($color->getGreen())
                        ->setBlue($color->getBlue())
                        ->setAlpha($color->getAlpha());
    }
912666
private function toRGB($color)
    {
        preg_match('/^#?([A-F0-9]{2})([A-F0-9]{2})([A-F0-9]{2})/i', $color, $m);

        return array(hexdec($m[1]), hexdec($m[2]), hexdec($m[3]));
    }
232570
public function color($color){
        $style = array(
            'font' => array(
                'color' => array('rgb'=>$color)
            )
        );
        $this->engine->getActiveSheet()->getStyle("$this->x$this->y")->applyFromArray($style);
        return $this;
    }
480837
public function color($color)
    {
        if ($color instanceof Collection) {
            $color = $color->toArray();
        }

        return $this->options([
            'color' => $color,
        ]);
    }
997220
public static function parse($color)
    {
        $hsl = '/hsl\(([0-9]{1,3}),\s*([0-9]{1,3})%,\s*([0-9]{1,3})%\)/';
        $rgb = '/rgb\(([0-9]{1,3}),\s*([0-9]{1,3}),\s*([0-9]{1,3})\)/';

        // HSL
        if (preg_match($hsl, $color, $m)) {
            return static::hsl((int)$m[1], (int)$m[2] / 100, (int)$m[3] / 100);
        } // RGB
        elseif (preg_match($rgb, $color, $m)) {
            return static::rgb((int)$m[1], (int)$m[2], (int)$m[3]);
        } // Hex
        else {
            return static::hex($color);
        };

    }
766928
public function getHslaString(Color $color)
    {
        return 'hsla('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%, ' . $color->alpha . ')';
    }
137074
public function getRgbaString(Color $color)
    {
        return 'rgba('. $color->red . ', ' . $color->green . ', ' . $color->blue . ', ' . $color->alpha . ')';
    }