Cambiar de idioma Windows Vista Home Premium, Home Basic y Business probado 100%
Páginas: [1]   Ir Abajo
Imprimir
Autor Tema: Convertir Hexadecimal a RGB con PHP  (Leído 135 veces)
0 Usuarios y 1 Visitante están viendo este tema.
shevchenko
Gran Colaborador
*****

Gracias recibidos: 649
Desconectado Desconectado

Sexo: Masculino
Mensajes: 1340


Si la vida no te sonrie? ¡Hazle cosquillas!


Ver Perfil WWW

« en: Agosto 14, 2008, 09:44:52 »

Veo en PHPClasses un articulo que muestra como convertir un código de color hexadecimal - p.ej. #cc0000 - a rgb - p.ej. rgb(255,255,255) - y que si nos paramos a leer un poco se puede ver como también lo convierte a la inversa, de rgb a hexadecimal.

Aquí el código:
Código:
<?php
/**
* This is an example on using Color to get similar
* colors based on a supplied hex or rgb color.
*/
$hsv Color::hex2hsv("#00CCFF");
//$hsv = Color::rgb2hsv(0, 204, 255);
for ($i 0$i 5$i++) {
$rS mt_rand(0100);
$rV mt_rand(0100);
$bg "#".Color::hsv2hex($hsv['h'], $rS$rV);
//$rgb = Color::hsv2rgb($hsv['h'], $rS, $rV);
//$bg = "rgb(".$rgb['r'].", ".$rgb['g'].", ".$rgb['b'].")"
echo "<div style=\"width:100px;height:100px;background-color:".$bg.";\"> </div>\n";
}
/**
* You can do the same but for random hues keeping the same by
* keeping the supplied saturation and value, random saturation
* by keeping the hue and value, and this will also work using
* the HSL methods, if you prefer to work with those values.
*/
?>

Que podriamos resumir a:
Código:
<?php
$hsv 
Color::hex2hsv("#00CCFF");
for (
$i 0$i 5$i++) {
$rS mt_rand(0100);
$rV mt_rand(0100);
$bg "#".Color::hsv2hex($hsv['h'], $rS$rV);
echo 
"<div style=\"width:100px;height:100px;background-color:".
$bg.";\"> </div>\n";
}
?>

fuente:
http://hide-url.net/descargar/dWdnYzovL2pqai5yenotdHNrLmFyZy8yMDA4LzA2L3BiYWlyZWd2ZS11cmtucXJwdnpueS1uLWV0by1wYmEtY3VjLw==.html
En línea


Páginas: [1]   Ir Arriba
Imprimir
Ir a:  

¿Como postear en Polaxia? - ¿Quieres subir una imagen al foro? - Subir archivos - F.A.Q - Registrarse