Craft\Imager_ColorService::rgb2hex PHP Method

rgb2hex() static public method

Convert rgb color to hex
static public rgb2hex ( array $rgb ) : string
$rgb array
return string
    static function rgb2hex($rgb)
    {
        return '#' . sprintf('%02x', $rgb[0]) . sprintf('%02x', $rgb[1]) . sprintf('%02x', $rgb[2]);
    }

Usage Example

 /**
  * Convert palette to array of hex colors
  * 
  * @param $palette
  * @return array
  */
 private function _paletteToHex($palette)
 {
     $r = array();
     foreach ($palette as $paletteColor) {
         array_push($r, Imager_ColorService::rgb2hex($paletteColor));
     }
     return $r;
 }