src/Util/Color.php
public static function colorToHex($color)
    {
        $colors = array(
            'maroon'    => '800000',
            'red'       => 'FF0000',
            'orange'    => 'FFA500',
            'yellow'    => 'FFFF00',
            'olive'     => '808000',
            'purple'    => '800080',
            'fuchsia'   => 'FF00FF',
            'white'     => 'FFFFFF',
            'lime'      => '00FF00',
            'green'     => '008000',
            'navy'      => '000080',
            'blue'      => '0000FF',
            'aqua'      => '00FFFF',
            'teal'      => '008080',
            'black'     => '000000',
            'silver'    => 'C0C0C0',
            'gray'      => '808080',
        );
        if (array_key_exists($color, $colors)) {
            return $colors[$color];
        }
        
        $color_pattern = '/rgb\((.*?)\)/';
        preg_match($color_pattern, $color, $matches);
        if (is_array($matches) && count($matches) > 0) {
            $rgb = explode(',', $matches[1]);
            if (is_array($rgb) && count($rgb) === 3) {
                return self::RGBToHex($rgb[0], $rgb[1], $rgb[2]);
            }
        }
        
        return $color;
    }
public static function colorToHex($color)
    {
        $colors = array(
            'maroon'    => '800000',
            'red'       => 'FF0000',
            'orange'    => 'FFA500',
            'yellow'    => 'FFFF00',
            'olive'     => '808000',
            'purple'    => '800080',
            'fuchsia'   => 'FF00FF',
            'white'     => 'FFFFFF',
            'lime'      => '00FF00',
            'green'     => '008000',
            'navy'      => '000080',
            'blue'      => '0000FF',
            'aqua'      => '00FFFF',
            'teal'      => '008080',
            'black'     => '000000',
            'silver'    => 'C0C0C0',
            'gray'      => '808080',
        );
        if (array_key_exists($color, $colors)) {
            return $colors[$color];
        }
        
        $color_pattern = '/rgb\((.*?)\)/';
        preg_match($color_pattern, $color, $matches);
        if (is_array($matches) && count($matches) > 0) {
            $rgb = explode(',', $matches[1]);
            if (is_array($rgb) && count($rgb) === 3) {
                return self::RGBToHex($rgb[0], $rgb[1], $rgb[2]);
            }
        }
        
        return $color;
    }
public static function colorToHex ( $ color ) { $ colors = array ( 'maroon' => '800000' , 'red' => 'FF0000' , 'orange' => 'FFA500' , 'yellow' => 'FFFF00' , 'olive' => '808000' , 'purple' => '800080' , 'fuchsia' => 'FF00FF' , 'white' => 'FFFFFF' , 'lime' => '00FF00' , 'green' => '008000' , 'navy' => '000080' , 'blue' => '0000FF' , 'aqua' => '00FFFF' , 'teal' => '008080' , 'black' => '000000' , 'silver' => 'C0C0C0' , 'gray' => '808080' , ) ; if ( array_key_exists ( $ color , $ colors ) ) { return $ colors [ $ color ] ; } $ color_pattern = '/rgb\((.*?)\)/' ; preg_match ( $ color_pattern , $ color , $ matches ) ; if ( is_array ( $ matches ) && count ( $ matches ) > 0 ) { $ rgb = explode ( ',' , $ matches [ 1 ] ) ; if ( is_array ( $ rgb ) && count ( $ rgb ) === 3 ) { return self :: RGBToHex ( $ rgb [ 0 ] , $ rgb [ 1 ] , $ rgb [ 2 ] ) ; } } return $ color ; }
Convert color name to hex
@param string $color Color
@return string
Convert color name to hex