3 Replies - 854 Views - Last Post: 04 July 2011 - 06:10 PM

#1 thephpdev  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 59
  • Joined: 01-July 11

HTML Color Code Combiner

Posted 04 July 2011 - 02:05 PM

Rather simple project but I find it pretty useful. Site

Here's the code in case anyone's interested:

<?php
$output_hex = "";
if (isset($_GET['hex1']) && isset($_GET['hex2'])) {
	$hex1 = str_replace("#", "", $_GET['hex1']);
	$hex2 = str_replace("#", "", $_GET['hex2']);
	$rgb1 = array();
	$rgb2 = array();
	$rgb1[0] = hexdec(substr($hex1, 0, 2));
	$rgb1[1] = hexdec(substr($hex1, 2, 2));
	$rgb1[2] = hexdec(substr($hex1, 4, 2));
	
	$rgb2[0] = hexdec(substr($hex2, 0, 2));
	$rgb2[1] = hexdec(substr($hex2, 2, 2));
	$rgb2[2] = hexdec(substr($hex2, 4));
	
	$finish = array();
	$finish[0] = ($rgb1[0] + $rgb2[0]) / 2;
	$finish[1] = ($rgb1[1] + $rgb2[1]) / 2;
	$finish[2] = ($rgb1[2] + $rgb2[2]) / 2;
	$output_hex = "";
	for ($i = 0; $i < 3; $i++) {
		if ($finish[$i] == 0) {
			$output_hex .= "00";
		} else {
			$output_hex .= dechex($finish[$i]);
		}
	}
}
?>
<html>
<title>Combine Codes</title>
<body>
<?php
if (isset($_GET['hex1']) && isset($_GET['hex2'])) {
	echo "Combined Hex: " . $output_hex . "<br />";
	echo "<table><tr><th>Color 1</th><th>Combined Color</th><th>Color 2</th></tr>";
	echo "<tr>";
	echo "<td style='width: 200px; height: 75px; background-color: " . $_GET['hex1'] . ";'>&nbsp;</td>";
	echo "<td style='width: 200px; height: 75px; background-color: " . $output_hex . ";'>&nbsp;</td>";
	echo "<td style='width: 200px; height: 75px; background-color: " . $_GET['hex2'] . ";'>&nbsp;</td>";
	echo "</tr>";
	echo "</table>";
}
?>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Color Code 1: <input type="text" name="hex1" size="7" maxlength="7"><br />
Color Code 2: <input type="text" name="hex2" size="7" maxlength="7"><br />
<input type="submit" value="Get Mixed Code">
</form>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: HTML Color Code Combiner

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: HTML Color Code Combiner

Posted 04 July 2011 - 03:28 PM

interesting. I wrote something similar in jQuery and HTML5 a while ago with a set of sliders =)
Was This Post Helpful? 0
  • +
  • -

#3 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 153
  • View blog
  • Posts: 1,867
  • Joined: 13-October 07

Re: HTML Color Code Combiner

Posted 04 July 2011 - 03:37 PM

neat, you can type in "red" and "blue" and it will show those colors but it won't combine them.
The hex values work fine though
Was This Post Helpful? 0
  • +
  • -

#4 thephpdev  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 59
  • Joined: 01-July 11

Re: HTML Color Code Combiner

Posted 04 July 2011 - 06:10 PM

That's a good idea on the colors, I'll add that on there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1