Converts a RGB array or the 3 r, g, b values into a hexadecimal color representation.

@param  array|integer $r RGB Array or the red bit value.
@param  int           $g The green bit value.
@param  int           $b The blue bit value
@return string|FALSE
542756
public static function Rgb2Hex( $r, int $g = -1, int $b = -1 )
   {

      if ( \is_array( $r ) )
      {

         if ( \count( $r ) != 3 )
         {
            return false;
         }

         \array_change_key_case( $r, \CASE_LOWER );

         if ( isset( $r[ 'r' ] ) && isset( $r[ 'g' ] ) && isset( $r[ 'b' ] ) )
         {
            $g = $r[ 'g' ];
            $b = $r[ 'b' ];
            $r = $r[ 'r' ];
         }
         else if ( isset( $r[ 'red' ] ) && isset( $r[ 'green' ] ) && isset( $r[ 'blue' ] ) )
         {
            $g = $r[ 'green' ];
            $b = $r[ 'blue' ];
            $r = $r[ 'red' ];
         }
         else
         {
            $rgb = $r;
            list( $r, $g, $b ) = $rgb;
         }

      }
      else if ( \preg_match( '~^(rgb\s*\()?(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)?$~', (string) $r, $m ) )
      {

         list( $ignore, $r, $g, $b ) = $m;
         if ( ! empty( $ignore ) )
         {
            unset( $ignore );
         }

      }
      else if ( ! \is_int( $r ) )
      {

         return false;

      }
      $r1 = \intval( $r );
      $g1 = \intval( $g );
      $b1 = \intval( $b );
      $r  = \dechex( $r1 < 0 ? 0 : ( $r1 > 255 ? 255 : $r1 ) );
      $g  = \dechex( $g1 < 0 ? 0 : ( $g1 > 255 ? 255 : $g1 ) );
      $b  = \dechex( $b1 < 0 ? 0 : ( $b1 > 255 ? 255 : $b1 ) );

      return \sprintf( '#%02s%02s%02s', $r, $g, $b );

   }
856325
public static final String toBrowserRGB(final int r, final int g, final int b)
    {
        return "rgb(" + fixRGB(r) + "," + fixRGB(g) + "," + fixRGB(b) + ")";
    }
1065159
def rgb_2_hex(self, r, g, b):
        
        return "#{:02X}{:02X}{:02X}".format(int(r * 255), int(g * 255), int(b * 255))
608020
public function initFromRgb($r, $g, $b)
    {
        $this->r = (int) $r;
        $this->g = (int) $g;
        $this->b = (int) $b;
        $this->a = 0;

        return $this;
    }
891491
public static function transformRGB($color = '#000000') {
		if (strlen($color) == 4) {
			$red = substr($color, 1, 1);
			$green = substr($color, 2, 1);
			$blue = substr($color, 3, 1);
			$red .= $red;
			$green .= $green;
			$blue .= $blue;
		} else {
			$red = substr($color, 1, 2);
			$green = substr($color, 3, 2);
			$blue = substr($color, 5, 2);
		}
		return array(
				hexdec($red),
				hexdec($green),
				hexdec($blue)
		);
	}
617508
public function rgb2hsl($r, $g, $b)
	{
		$h = 0;

		$min = min($r, $g, $b);
		$max = max($r, $g, $b);

		$diff = $max - $min;
		$l = ($max + $min) / 2;

		if ($diff == 0) {
			$h = 0;
			$s = 0;
		} else {

			if ($l < 0.5) {
				$s = $diff / ($max + $min);
			} else {
				$s = $diff / (2 - $max - $min);
			}

			$rDiff = ((($max - $r) / 6) + ($diff / 2)) / $diff;
			$gDiff = ((($max - $g) / 6) + ($diff / 2)) / $diff;
			$bDiff = ((($max - $b) / 6) + ($diff / 2)) / $diff;

			if ($r == $max) {
				$h = $bDiff - $gDiff;
			} elseif ($g == $max) {
				$h = (1 / 3) + $rDiff - $bDiff;
			} elseif ($b == $max) {
				$h = (2 / 3) + $gDiff - $rDiff;
			}

			if ($h < 0) {
				++$h;
			}

			if ($h > 1) {
				--$h;
			}
		}

		return [$h, $s, $l];
	}
123651
def _hex_to_rgb(color):
    
    if color[0] == '#':
        color = color[1:]
    if len(color) == 3:
        color = color[0] * 2 + color[1] * 2 + color[2] * 2
    if len(color) != 6:
        raise ValueError('Input #{0} is not in #RRGGBB format'.format(color))
    return [int(n, 16) for n in (color[:2], color[2:4], color[4:])]
831680
def rgb256(r, g, b):
    '''
    
    '''
    grey = False
    poss = True
    step = 2.5

    while poss: # As long as the colour could be grey scale
        if r < step or g < step or b < step:
            grey = r < step and g < step and b < step
            poss = False

        step += 42.5

    if grey:
        colour = 232 + int(float(sum([r, g, b]) / 33.0))
    else:
        colour = sum([16] + [int (6 * float(val) / 256) * mod
            for val, mod in ((r, 36), (g, 6), (b, 1))])

    return sequence('m', fields=3)(38, 5, colour)
276317
public function setLineColor($r, $g, $b)
    {

        $this->ink['line'] = imagecolorallocate($this->im, $r, $g, $b);
    }
604670
public static function hexrgb( $hexstr ) {
		if ( !strstr($hexstr, '#') ) {
			$hexstr = '#'.$hexstr;
		}
		if ( strlen($hexstr) == 4 ) {
			$hexstr = '#'.$hexstr[1].$hexstr[1].$hexstr[2].$hexstr[2].$hexstr[3].$hexstr[3];
		}
		$int = hexdec($hexstr);
		return array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
	}
1060451
public function setBackgroundColor($r, $g, $b)
    {
        $this->backgroundColor = array($r, $g, $b);

        return $this;
    }
199165
public function setAxisColor($r, $g, $b)
    {
        $this->ink['axis'] = imagecolorallocate($this->im, $r, $g, $b);
    }
56690
def _hexvalue_to_rgb(hexvalue):
        
        r = int(hexvalue[0:2], 16)
        g = int(hexvalue[2:4], 16)
        b = int(hexvalue[4:6], 16)

        return (r, g, b)
106203
public function rgb($red, $green, $blue)
    {
        $this->setValues($red, $green, $blue);

        return $this;
    }
1034957
private function setPixel($r, $g, $b, $a = null)
    {
        $a = $a ?? 1;

        return $this->pixel = new \ImagickPixel(
            sprintf('rgba(%d, %d, %d, %.2F)', $r, $g, $b, $a)
        );
    }
240768
def sgr_fg_rgb(r, g, b):
        """"""
        assert r in range(256)
        assert g in range(256)
        assert b in range(256)
        return '38;2;{};{};{}'.format(r, g, b)
1141771
public static final Color hex2RGB(final String hex)
    {
        String r, g, b;

        final int len = hex.length();

        if (len == 7)
        {
            r = hex.substring(1, 3);

            g = hex.substring(3, 5);

            b = hex.substring(5, 7);
        }
        else if (len == 4)
        {
            r = hex.substring(1, 2);

            g = hex.substring(2, 3);

            b = hex.substring(3, 4);

            r = r + r;

            g = g + g;

            b = b + b;
        }
        else
        {
            return null;// error - invalid length
        }
        try
        {
            return new Color(Integer.valueOf(r, 16), Integer.valueOf(g, 16), Integer.valueOf(b, 16));
        }
        catch (final NumberFormatException ignored)
        {
            return null;
        }
    }