2016-09-08 4 views
0

Я хотел бы отобразить значение RGB изображений в процентах.Как отобразить значение rgb изображения в процентах

Например, если цвет в гексагоне #000000, как отобразить его как% кода (в процентах), например, rgb (0%, 0%, 0%)?

+0

ли вы Google ?, если да, то вы проверили это? http://stackoverflow.com/questions/15202079/convert-hex-color-to-rgb-values-in-php – Neat

ответ

0

попробовать это,

function hex2rgb($hex) { 
    $hex = str_replace("#", "", $hex); 

    if(strlen($hex) == 3) { 
     $r = hexdec(substr($hex,0,1).substr($hex,0,1)); 
     $g = hexdec(substr($hex,1,1).substr($hex,1,1)); 
     $b = hexdec(substr($hex,2,1).substr($hex,2,1)); 
    } else { 
     $r = hexdec(substr($hex,0,2)); 
     $g = hexdec(substr($hex,2,2)); 
     $b = hexdec(substr($hex,4,2)); 
    } 
    $rgb = array($r, $g, $b); 
    //return implode(",", $rgb); // returns the rgb values separated by commas 
    return $rgb; // returns an array with the rgb values 
} 

ВЫВОД:

Array ([0] => 204 [1] => 204 [2] => 0) 
//rgb(204,204,0) 

DEMO

Смежные вопросы