Skip to content

Instantly share code, notes, and snippets.

@dkobia
Forked from brianherbert/colormixer.php
Created December 8, 2010 20:08
Show Gist options
  • Save dkobia/733824 to your computer and use it in GitHub Desktop.
Save dkobia/733824 to your computer and use it in GitHub Desktop.
<?php
$hex1 = 'FF0000';
$hex2 = '0000FF';
$hex3 = '';
$r1 = base_convert($hex1{0}.$hex1{1},16,10);
$g1 = base_convert($hex1{2}.$hex1{3},16,10);
$b1 = base_convert($hex1{4}.$hex1{5},16,10);
$r2 = base_convert($hex2{0}.$hex2{1},16,10);
$g2 = base_convert($hex2{2}.$hex2{3},16,10);
$b2 = base_convert($hex2{4}.$hex2{5},16,10);
$r3 = round(($r1 + $r2) / 2);
$g3 = round(($g1 + $g2) / 2);
$b3 = round(($b1 + $b2) / 2);
$r3 = (string)base_convert($r3,10,16);
$g3 = (string)base_convert($g3,10,16);
$b3 = (string)base_convert($b3,10,16);
if($r3 == 0) $r3 = '00';
if($b3 == 0) $b3 = '00';
if($g3 == 0) $g3 = '00';
$hex3 = $r3.$g3.$b3;
?>
<div style="width:100px;height:100px;float:left;background-color:#<?php echo $hex1; ?>"><?php echo $hex1; ?></div>
<div style="float:left;font-size:72px;">&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;</div>
<div style="width:100px;height:100px;float:left;background-color:#<?php echo $hex2; ?>"><?php echo $hex2; ?></div>
<div style="float:left;font-size:72px;">&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;</div>
<div style="width:100px;height:100px;float:left;background-color:#<?php echo $hex3; ?>"><?php echo $hex3; ?></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment