RE:Convertidor de Colores
/*
decodifoca un código hexadecimal HTML en un array de valores R,G, y B.
acepta estos formatos: (insensible a mayúsculas) #ffffff, ffffff, #fff, fff
*/
function hex_to_rgb($hex)
{
// remueve '#'
if(substr($hex,0,1) == '#')
$hex = substr($hex,1) ;
// expande el formato corto ('fff')
if(strlen($hex) == 3)
{
$hex = substr($hex,0,1) . substr($hex,0,1) .
substr($hex,1,1) . substr($hex,1,1) .
substr($hex,2,1) . substr($hex,2,1) ;
}
if(strlen($hex) != 6)
echo "Error: Color invalido ".$hex;
// convertir
$rgb['red'] = hexdec(substr($hex,0,2)) ;
$rgb['green'] = hexdec(substr($hex,2,2)) ;
$rgb['blue'] = hexdec(substr($hex,4,2)) ;
return $rgb ;
}