Command image colorize

@param string $hexColor

@return void
510023
protected function imageColorize($hexColor)
    {
        if (strlen($hexColor) != 6 || !preg_match('![0-9abcdef]!i', $hexColor)) {
            throw new BadMethodCallException('Invalid parameter color for command "colorize"');
        }
        $color = $this->image->palette()->color('#' . $hexColor);
        
        $this->image->effects()->colorize($color);
    }
870759
public function setBackgroundHexColor($backgroundHexColor)
    {
        if ( is_null($this->frontColor) ) {
            $this->backColor = new Color;
        }

        $this->backColor->hex($backgroundHexColor);

        return $this;
    }
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;
	}
1170909
public function setColor($color)
    {
        if (!empty($color)) {
            $this->color = $this->convertColor($color);
        }

        return $this;
    }
1078792
private static function hexToRgb(string $color): array
    {
        $color = ltrim($color, '#');

        // Convert the shorthand hex to the full hex (09F => 0099FF)
        if (strlen($color) == 3) {
            $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
        }

        return [
            'r' => (int)hexdec(substr($color, 0, 2)),
            'g' => (int)hexdec(substr($color, 2, 2)),
            'b' => (int)hexdec(substr($color, 4, 2)),
        ];
    }
1131925
protected function _color_luminance( $hex, $percent ) {
		$hex        = $this->_hex_normalization( $hex );
		$hue        = $this->_get_hue( $hex );
		$saturation = $this->_get_saturation( $hex );
		$luminance  = $this->_get_luminance( $hex );

		// Add luminance.
		$luminance += $percent * 100;
		$luminance  = ( 100 < $luminance ) ? 100 : $luminance;
		$luminance  = ( 0 > $luminance ) ? 0 : $luminance;

		$hex = $this->_convert_hsl_to_hex( $hue, $saturation, $luminance );
		return $hex;
	}
397051
public function setForegroundHexColor($foregroundHexColor)
    {
        if ( is_null($this->frontColor) ) {
            $this->frontColor = new Color;
        }

        $this->frontColor->hex($foregroundHexColor);

        return $this;
    }
1044617
private function convertColor($hex, $alpha = false)
    {
        $hex = str_replace('#', '', $hex);
        $length = strlen($hex);
        $rgb['0'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
        $rgb['1'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
        $rgb['2'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
        if ($alpha) {
            $rgb['2'] = $alpha;
        }

        return $rgb;
    }
857975
public function setBgColor($color)
    {
        if (!empty($color)) {
            $this->bgColor = $this->convertColor($color);
        }

        return $this;
    }
372196
public function addColor($color)
    {
        if ( ! $color instanceof Color ) {
            $color = new Color($color);
        }

        $this->colors []= $color;
    }
1229350
public function getArgbHexString(Color $color)
    {
        $alpha = dechex(255 * $color->alpha);
        return '#' . $alpha . $color->hex;
    }
123951
public function setColor($x, $y, $color) {
		return imagesetpixel($this->image, $x, $y, $this->getColorWithRGB($color));
	}
302526
public static function hexToRgb($hex) {
    if (!self::validateHex($hex)) {
      throw new \InvalidArgumentException("'$hex' is not a valid hex value.");
    }

    // Ignore '#' prefixes.
    $hex = ltrim($hex, '#');

    // Convert shorthands like '#abc' to '#aabbcc'.
    if (strlen($hex) == 3) {
      $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
    }

    $c = hexdec($hex);

    return array(
      'red' => $c >> 16 & 0xFF,
      'green' => $c >> 8 & 0xFF,
      'blue' => $c & 0xFF,
    );
  }
559726
protected function _prepColor($color) {
		if (strpos($color, '#') !== false) {
			return str_replace('#', '0x', $color);
		}
		if (is_numeric($color)) {
			return '0x' . $color;
		}
		return $color;
	}
1046900
public static function colourBrightness($hex, $percent)
    {
        // Work out if hash given
        $hash = '';
        if (mb_stristr($hex, '#')) {
            $hex = str_replace('#', '', $hex);
            $hash = '#';
        }
        /// HEX TO RGB
        $rgb = [hexdec(mb_substr($hex, 0, 2)), hexdec(mb_substr($hex, 2, 2)), hexdec(mb_substr($hex, 4, 2))];
        //// CALCULATE
        for ($i = 0; $i < 3; ++$i) {
            // See if brighter or darker
            if ($percent > 0) {
                // Lighter
                $rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1 - $percent));
            } else {
                // Darker
                $positivePercent = $percent - ($percent * 2);
                $rgb[$i] = round($rgb[$i] * $positivePercent) + round(0 * (1 - $positivePercent));
            }
            // In case rounding up causes us to go to 256
            if ($rgb[$i] > 255) {
                $rgb[$i] = 255;
            }
        }
        //// RBG to Hex
        $hex = '';
        for ($i = 0; $i < 3; ++$i) {
            // Convert the decimal digit to hex
            $hexDigit = dechex($rgb[$i]);
            // Add a leading zero if necessary
            if (1 === mb_strlen($hexDigit)) {
                $hexDigit = '0'.$hexDigit;
            }
            // Append to the hex string
            $hex .= $hexDigit;
        }

        return $hash.$hex;
    }
615091
protected function hexToRgb($hex)
    {
        if (! isset($this->colorCache[$hex])) {
            $this->colorCache[$hex] = [
                'r' => hexdec(substr($hex, 0, 2)),
                'g' => hexdec(substr($hex, 2, 2)),
                'b' => hexdec(substr($hex, 4, 2))
            ];
        }

        return $this->colorCache[$hex];
    }
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));
    }