Xnote.com Technical Forums Last active: Never
Not logged in [Login - Register]
Go To Bottom

Printable Version | Subscribe | Add to Favourites  
Author: Subject: php convert rgb to hex color
Alan Fullmer
Super Administrator
*********




Posts: 62
Registered: 8-12-2004
Member Is Offline

Mood: No Mood

[*] posted on 13-5-2007 at 02:42 PM
php convert rgb to hex color



<?php
function rgbhtml($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;
}
?>




View User's Profile Visit User's Homepage View All Posts By User U2U Member


Go To Top


Powered by XMB
Developed By Aventure Media & The XMB Group © 2002-2007