Formats a buffer with a specified ANSI color sequence if colors are enabled.

@author Sebastian Bergmann <sebastian@phpunit.de>
@param  string $color
@param  string $buffer
@return string
329227
public static function formatWithColor(string $color, string $buffer) : string
    {
        $codes   = array_map('trim', explode(',', $color));
        $lines   = explode("\n", $buffer);
        $padding = max(array_map('strlen', $lines));

        $styles = [];
        foreach ($codes as $code) {
            $styles[] = self::$ansiCodes[$code];
        }
        $style = sprintf("\x1b[%sm", implode(';', $styles));

        $styledLines = [];
        foreach ($lines as $line) {
            $styledLines[] = strlen($line) ? $style . str_pad($line, $padding) . "\x1b[0m" : '';
        }

        return implode(PHP_EOL, $styledLines);
    }
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);
        };

    }
422947
public function setBuffer($buffer)
    {
        $this->buffer = $buffer;

        $this->seq       = $this->buffer->readShort(self::SEQ_INDEX);
        $this->timestamp = $this->buffer->readInt(self::TIMESTAMP_INDEX);
        $this->ssrc      = $this->buffer->readInt(self::SSRC_INDEX);

        return $this;
    }
823915
public function setColor($color)
    {
        if (null === $color) {
            return $this;
        }

        $this->color = $this->convertColor($color);

        return $this;
    }
484589
public function output($buffer) {
        if (!$buffer && !$this->__result) {
            return '';
        }

        $out = '';
        // Always include the output generated by the expression first
        if ($buffer) {
            $out .= Garp_Cli::lineOut($buffer, null, true, false);
        }

        // And follow-up with the populated result, if any
        if ($this->__result) {
            // Try to format as user-friendly as possible
            $isObjWithToArray = is_object($this->__result) &&
                method_exists($this->__result, 'toArray');
            $this->__result = $isObjWithToArray ? $this->__result->toArray() : $this->__result;
            $this->__result = var_export($this->__result, true);
            $out .= Garp_Cli::lineOut($this->__result, Garp_Cli::BLUE, true, false);
        }

        return $out;
    }
1235411
protected function getColorMapOrAsHex(string $color)
    {
        return isset($this->colorMap[$color]) ? $this->colorMap[$color] : $color;
    }
193603
public function set_bg_color($color) {
        if (!isset($this->format['fill']['type'])) {
            $this->format['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID;
        }
        $this->format['fill']['color']['rgb'] = $this->parse_color($color);
    }
640820
protected function _set_fill_color($color) {
    if($this->_last_fill_color == $color)
      return;

    $this->_last_fill_color = $color;

      if (isset($color[3])) {
      $type = "cmyk";
      list($c1, $c2, $c3, $c4) = array($color[0], $color[1], $color[2], $color[3]);
    }
    elseif (isset($color[2])) {
      $type = "rgb";
      list($c1, $c2, $c3, $c4) = array($color[0], $color[1], $color[2], null);
    }
    else {
      $type = "gray";
      list($c1, $c2, $c3, $c4) = array($color[0], $color[1], null, null);
    }
    
    $this->_pdf->setcolor("fill", $type, $c1, $c2, $c3, $c4);
  }
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]);
	}
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]));
    }
1258394
protected function normalize_color($color) {
        if (is_string($color)) {
            $color = trim($color, '#');
            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 false;
            }
            return array(
                'r' => hexdec($r),
                'g' => hexdec($g),
                'b' => hexdec($b),
                'a' => 0
            );
        } elseif (is_array($color) && (count($color) == 3 || count($color) == 4)) {
            if (isset($color['r'], $color['g'], $color['b'])) {
                return array(
                    'r' => $this->keep_within($color['r'], 0, 255),
                    'g' => $this->keep_within($color['g'], 0, 255),
                    'b' => $this->keep_within($color['b'], 0, 255),
                    'a' => $this->keep_within(isset($color['a']) ? $color['a'] : 0, 0, 127)
                );
            } elseif (isset($color[0], $color[1], $color[2])) {
                return array(
                    'r' => $this->keep_within($color[0], 0, 255),
                    'g' => $this->keep_within($color[1], 0, 255),
                    'b' => $this->keep_within($color[2], 0, 255),
                    'a' => $this->keep_within(isset($color[3]) ? $color[3] : 0, 0, 127)
                );
            }
        }
        return false;
    }
744485
private function _allocate_color($color)
    {
        $a = isset($color["alpha"]) ? $color["alpha"] : 1;

        if (isset($color["c"])) {
            $color = Helpers::cmyk_to_rgb($color);
        }

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

        $r *= 255;
        $g *= 255;
        $b *= 255;
        $a = 127 - ($a * 127);

        // Clip values
        $r = $r > 255 ? 255 : $r;
        $g = $g > 255 ? 255 : $g;
        $b = $b > 255 ? 255 : $b;
        $a = $a > 127 ? 127 : $a;

        $r = $r < 0 ? 0 : $r;
        $g = $g < 0 ? 0 : $g;
        $b = $b < 0 ? 0 : $b;
        $a = $a < 0 ? 0 : $a;

        $key = sprintf("#%02X%02X%02X%02X", $r, $g, $b, $a);

        if (isset($this->_colors[$key])) {
            return $this->_colors[$key];
        }

        if ($a != 0) {
            $this->_colors[$key] = imagecolorallocatealpha($this->get_image(), $r, $g, $b, $a);
        } else {
            $this->_colors[$key] = imagecolorallocate($this->get_image(), $r, $g, $b);
        }

        return $this->_colors[$key];
    }
712048
public function setColor($color)
	{
		if (is_array($color))
		{
			$this->color[0] = $color[0];
			$this->color[1] = $color[1];
			$this->color[2] = $color[2];
		}
		else
		{
			$color = ltrim($color, '#');

			$this->color[0] = hexdec(substr($color, 0, 2));
			$this->color[1] = hexdec(substr($color, 2, 2));
			$this->color[2] = hexdec(substr($color, 4, 2));
		}

		return $this;
	}
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)
        );
    }
784258
public static function printColor ($string, $color = 'white')
		{
			$code = 'w';
			switch ($color)
			{
				case 'black':
					$code = 'k';
					break;
				case 'cyan':
					$code = 'c';
					break;
				case 'gray':
				case 'grey':
					$code = 'K';
					break;
				case 'green':
					$code = 'g';
					break;
				case 'magenta':
					$code = 'm';
					break;
				case 'red':
					$code = 'r';
					break;
				case 'yellow':
					$code = 'y';
					break;
			}
			self::stdout(self::renderColoredString("%" . $code . $string . "%n\n"));
		}
817138
public function getColorCode($color)
    {
        if (!$this->enabled) {
            return '';
        }
        if (!isset($this->colors[$color])) {
            throw new Exception("No such color $color");
        }

        return $this->colors[$color];
    }
215505
protected function initColor($color, $default)
    {
        if ($color == null) {
            return new Securimage_Color($default);
        } else if (is_string($color)) {
            try {
                return new Securimage_Color($color);
            } catch(Exception $e) {
                return new Securimage_Color($default);
            }
        } else if (is_array($color) && sizeof($color) == 3) {
            return new Securimage_Color($color[0], $color[1], $color[2]);
        } else {
            return new Securimage_Color($default);
        }
    }