<?php function rgb2hexa($r, $g=-1, $b=-1) { if (is_array($r) && sizeof($r) == 3) list($r, $g, $b) = $r; $r intval($r); $g intval($g); $b = intval($b); $r = dechex($r<0?0:($r>255?255:$r)); $g = dechex($g<0?0:($g>255?255:$g)); $b = dechex($b<0?0:($b>255?255:$b)); $color = (strlen($r) < 2?'0':'').$r; $color .= (strlen($g) < 2?'0':'').$g; $color .= (strlen($b) < 2?'0':'').$b; return '#'.$color; } $macouleur = rgb2hexa(rand(0, 255), rand(0, 255), rand(0, 255)); ?>
<?php function randHexaColor() { return sprintf("#%02X%02X%02X", rand(0,255), rand(0,255), rand(0,255)); } echo randHexaColor(); ?>
if (is_array($r) && sizeof($r) == 3) list($r, $g, $b) = $r;
<?php rgb2hexa(array(255, 200, 0)); ?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question