Jump to content

Recommended Posts

function toHex($N) {
if ($N==NULL) return "00";
if ($N==0) return "00";
$N=max(0,$N); 
$N=min($N,255); 
$N=round($N);
$string = "0123456789ABCDEF";
$val = (($N-$N%16)/16);
$s1 = $string{$val};
$val = ($N%16);
$s2 = $string{$val};
return $s1.$s2;
}



function rgb2hex($r,$g,$b){
return toHex($r).toHex($g).toHex($b);
}

function hex2rgb($N){
$N = trim($N,"#");
$dou = str_split($N,2);
return array(
	"R" => hexdec($dou[0]), 
	"G" => hexdec($dou[1]), 
	"B" => hexdec($dou[2])
);
}




echo rgb2hex(106,48,48);
echo '<p> </p>';
print_r(hex2rgb("6A3030"));

In color theory, two colors are called complementary if, when mixed in the proper proportion, they produce a neutral color (grey, white, or black).

 

http://en.wikipedia.org/wiki/Complimentary_colors

 

So, if $c1 and $c2 are complimentary

<?php
$c1 = '00FF00';
list ($r, $g, $b) = sscanf($c1,'%2X%2X%2X');

$c2 = sprintf('%02X%02X%02X', 255-$r, 255-$g, 255-$b);
echo "<div style='background-color: #$c1; height:10px'>$c1 <span style='color:#FFF'>$c1</span></div>";
echo "<div style='background-color: #$c2; height:10px'>$c2 <span style='color:#FFF'>$c2</span></div>";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.