Loads a color object from an rgb or rgba string

@param object $color Color object
@param mixed
@return object Color object
327896
public function loadRgbString(Color $color, $subject)
    {
        $subject = trim($subject);

        $subject = str_replace(array('rgba', 'rgb', '(', ')', ';', ' '), '', $subject);

        $rgbnum = explode(',', $subject);

        if (count($rgbnum) !== 3 && count($rgbnum) !== 4) {
            return false;
        }

        foreach ($rgbnum as &$val) {
            $val = floatval(trim($val));
        }

        $rgb = array(
            'red' => $rgbnum[0],
            'green' => $rgbnum[1],
            'blue' => $rgbnum[2]
        );

        if (isset($rgbnum[3])) {
            $rgb['alpha'] = $rgbnum[3];
        }

        $color->bulkUpdate($rgb);

        return $color;
    }
65537
protected static function getMixedColorAsRgb($color)
	{
		if (is_array($color)) {
			if (!static::validateRgbColor($color)) return false;
			return $color;
		} else {
			return static::hexToRgb($color);
		}
	}
1103567
public static function fromRgbString(string $string) : Colour
    {
        list($r, $g, $b) = ColourStringParser::parseRgbString($string);

        return new self($r, $g, $b);
    }
184360
public static function fromRGBString($color)
    {
        $color = rtrim($color, "rgb (\t)");
        $rgb = preg_split('\s+,\s+', $color);

        $c = new self();
        list($c->r, $c->g, $c->b) = array_map('intval', $rgb);

        return $c;
    }
1170909
public function setColor($color)
    {
        if (!empty($color)) {
            $this->color = $this->convertColor($color);
        }

        return $this;
    }
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);
    }
1235411
protected function getColorMapOrAsHex(string $color)
    {
        return isset($this->colorMap[$color]) ? $this->colorMap[$color] : $color;
    }
646325
protected function getColor($im, $color) {
        if ($color === self::COLOR_BG) {
            return $this->colorBg->allocate($im);
        } else {
            return $this->colorFg->allocate($im);
        }
    }
573998
public function getRgbByColor($color) {
		$result = imagecolorsforindex($this->image, $color);
		return array(
			$result['red'],
			$result['green'],
			$result['blue']
		);
	}
830800
protected function background($color = null)
    {
        if (is_string($color)) {
            $this->commands['-background "#%s"'] = [trim($color, '#')];
        }
        return $this;
    }
208334
protected function toHex($color)
	    {
	        $rgb = $this->getRGBComponents($color);

	        return sprintf('#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]);
	    }
1024089
public function setColor($color)
    {
        $allowedValues = $this->getColorAllowableValues();
        if (!is_null($color) && !in_array($color, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'color', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['color'] = $color;

        return $this;
    }
806558
public function fill_color( $color, $alpha = 1 ) 
	{
		$alpha = $alpha * 127;

		// parse the color
		$color = CCColor::create( $color );
		$color = imagecolorallocatealpha( $this->image_context, $color->RGB[0], $color->RGB[1], $color->RGB[2], $alpha );

		// run image fill
		imagefill( $this->image_context, 0, 0, $color );

		return $this;
	}
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";
	}
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);
        };

    }
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)
        );
    }
90104
public static function getColorCode($color, $options = array())
    {
        $code = (int) $color;
        if (is_string($color)) {
            $options = array_merge(explode('+', strtolower($color)), $options);
            $color = array_shift($options);
            if (!isset(self::$colors[$color])) {
                throw new ConsoleException("Unknown color '$color'");
            }
            $code = self::$colors[$color];
        }
        foreach ($options as $opt) {
            $opt = strtolower($opt);
            if (!isset(self::$options[$opt])) {
                throw new ConsoleException("Unknown option '$color'");
            }
            $code = $code | self::$options[$opt];
        }
        return $code;
    }