hex to rgba

@param hex $hex
@param int $percent
@return rgba
504361
public static function rgba( $hex, $percent ) {
		$hex = static::_hex_normalization( $hex );
		$rgba = [];

		for ( $i = 0; $i < 3; $i ++ ) {
			$dec = hexdec( substr( $hex, $i * 2, 2 ) );
			$rgba[] = $dec;
		}

		$rgba = implode( ',', $rgba );
		$rgba = "rgba({$rgba}, $percent)";

		return $rgba;
	}
479383
def text_colour_for_hex(hexx, percent=50, dark='#000000', light='#ffffff'):
    
    return light if hex_is_dark(hexx, percent=percent) else dark
384840
protected static function uni2utf8($hex)
    {

        if($hex < 0x80)
            return chr($hex);
        else if($hex < 0x800)
            return chr(0xc0 | ($hex >>  6)).chr(0x80 | ( $hex & 0x3f));
        else if($hex < 0x10000)
            return chr(0xe0 | ($hex >> 12)).chr(0x80 | (($hex >> 6  ) & 0x3f)).chr(0x80 | ($hex & 0x3f));
        else if($hex < 0x200000)
            return chr(0xf0 | ($hex >> 18)).chr(0x80 | (($hex >> 12 ) & 0x3f)).chr(0x80 | (($hex >> 6) & 0x3f)).chr(0x80 | ($hex & 0x3f));

        return false;
    }
295597
function rgb($color) {
		if (is_string($color))
			$color=hexdec($color);
		$hex=str_pad($hex=dechex($color),$color<4096?3:6,'0',STR_PAD_LEFT);
		if (($len=strlen($hex))>6)
			user_error(sprintf(self::E_Color,'0x'.$hex),E_USER_ERROR);
		$color=str_split($hex,$len/3);
		foreach ($color as &$hue) {
			$hue=hexdec(str_repeat($hue,6/$len));
			unset($hue);
		}
		return $color;
	}
650872
def rgb_to_hex(rgba):
    
    rgba = rgba.split('/')
    hex_value = '#' + rgba[0][:2] + rgba[1][:2] + rgba[2][:2]
    return hex_value
158147
public static function hex($hex)
    {
        // RGB Hex -> RGB
        static::hex2rgb($hex, $r, $g, $b);

        return static::rgb($r, $g, $b);
    }
336535
def _hex_to_rgba(hexs):
    """"""
    hexs = np.atleast_1d(np.array(hexs, '|U9'))
    out = np.ones((len(hexs), 4), np.float32)
    for hi, h in enumerate(hexs):
        assert isinstance(h, string_types)
        off = 1 if h[0] == '#' else 0
        assert len(h) in (6+off, 8+off)
        e = (len(h)-off) // 2
        out[hi, :e] = [int(h[i:i+2], 16) / 255.
                       for i in range(off, len(h), 2)]
    return out
891557
private static function _get_hue( $hex ) {
		$red   = hexdec( substr( $hex, 0, 2 ) );
		$green = hexdec( substr( $hex, 2, 2 ) );
		$blue  = hexdec( substr( $hex, 4, 2 ) );

		if ( $red === $green && $red === $blue ) {
			return 0;
		}

		$hue = static::_get_hue_based_max_rgb( $red, $green, $blue );

		if ( 0 > $hue ) {
			$hue += 360;
		}

		return $hue;
	}
63475
static function FromArgbHex($hex)
    {
        $cleanHex = ltrim($hex, '#');
        $a = hexdec(substr($cleanHex, 0, 2));
        $r = hexdec(substr($cleanHex, 2, 2));
        $g = hexdec(substr($cleanHex, 4, 2));
        $b = hexdec(substr($cleanHex, 6, 2));
        return new self($a, $r, $g, $b);
    }
83398
def rgb_to_hex(color):
    
    rgb = eval(color.replace('rgb', ''))
    # return '#'+''.join(map(chr, rgb)).encode('hex')
    return '#' + ''.join(['{0:02x}'.format(x).upper() for x in rgb])
809046
private function rgbToHex(int $r, int $g, int $b): string
    {
        return sprintf('#%02x%02x%02x', $r, $g, $b);
    }
1355864
function(hex, opacity) {
  let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex;
}
150975
public static function fromHex($hex)
  {
    if(strlen($hex) != 2)
    {
      throw new TeamSpeak3_Helper_Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
    }

    return new self(chr(hexdec($hex)));
  }
1118744
function hexaToRgba(hex) {
  if (hex.length === 3) {
    hex += "f"
  }
  if (hex.length === 4) {
    var h0 = hex.charAt(0)
    var h1 = hex.charAt(1)
    var h2 = hex.charAt(2)
    var h3 = hex.charAt(3)
    hex = h0 + h0 + h1 + h1 + h2 + h2 + h3 + h3
  }
  if (hex.length === 6) {
    hex += "ff"
  }
  var rgb = []
  for (var i = 0, l = hex.length; i < l; i += 2) {
    rgb.push(Math.round(parseInt(hex.substr(i, 2), 16) / (i === 6 ? 255 : 1) * DECIMAL_PRECISION) / DECIMAL_PRECISION)
  }

  return color({r: rgb[0], g: rgb[1], b: rgb[2], a: rgb[3]}).rgbaString()
}
1213306
public function tint($percent = 50)
    {
        $clone = clone $this;
        $white = $clone->toRgb()->red(255)->green(255)->blue(255);
        return $this->mix($white, $percent);
    }
927506
public function normalizeHex($hex)
	{
		if(preg_match('/^(#?[a-f0-9]{3}){1,2}$/i', $hex) === 0)
		{
			throw new InvalidArgumentException(vsprintf('Invalid HEX value [ %s ].', [$hex]));
		}

		return (strpos($hex, '#') !== 0) ? '#' . $hex : $hex;
	}
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;
    }