Location: PHPKode > scripts > GD Gradient Generator > gd-gradient-generator/gradientgd.box.php
<?php
	/**
	 * Color preview
	 * Remove delete feature if field is empty and only apply if its the last field
	 * Add a feature to use last post code as some sort of backup when "making"
	 * Make output type
	 * Color picker
	 */

	session_start();

	require_once('./gradientgd.class.php');

	if($_REQUEST['do'] == 'make')
	{
		@set_time_limit(0);

		# $_POST = unserialize($_SESSION['postcode']);

		$gradient =& new GradientGD($_POST['size_width'], $_POST['size_height']);

		$gradient->set_option('imagetype', 'jpg');
		$gradient->set_option('colorhandler', 'RGB');
		$gradient->set_option('reverse', false);

		$gradient->set_color(explode(',', str_replace(' ', '', $_POST['color_start'])), 'start');
		$gradient->set_color(explode(',', str_replace(' ', '', $_POST['color_end'])), 'end');

		if(is_array($_POST['color_multiple']) && sizeof($_POST['color_multiple']))
		{
			foreach($_POST['color_multiple'] as $multi => $value)
			{
				$_POST['color_multiple'][$multi] = explode(',', str_replace(' ', '', $value));
			}

			$gradient->set_color($_POST['color_multiple'], 'middle');
		}
/*
		$gradient->set_color(Array($_POST['color_multiple']), 'middle');
*/
/*
		$gradient->set_color(Array(
						Array(222, 0, 255), 
						Array(123, 0 ,255), 
						Array(24, 0, 255), 
						Array(0, 57, 255), 
						Array(0, 156, 255), 
						Array(0, 255, 255), 
						Array(0, 255, 156), 
						Array(0, 255, 57), 
						Array(24, 255, 0), 
						Array(140, 255, 0), 
						Array(239, 255, 0), 
						Array(255, 189, 0), 
						Array(255, 90, 0), 

						), 'middle');
*/

		$gradient->generate();

		if(!isset($_SESSION['postcode']))
		{
			$_SESSION['postcode'] = serialize($_POST);
		}
	}
	else
	{
		echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
<html>
	<head>
		<title>Gradient GD Generator</title>

		<script type="text/javascript">
		<!--
		var multiple_array = Array();

		function multiple_new(defaultvalue)
		{
			multiple_array[multiple_array.length] = defaultvalue;
			multiple_generate();
		}
		function multiple_modify(colorid, newvalue)
		{
			var colorinstance = document.getElementById('color_' + colorid);

			if(newvalue == "")
			{
				multiple_delete(colorid);
			}
			else
			{
				multiple_array[colorid] = newvalue;
				multiple_generate();
			}
		}
		function multiple_delete(colorid)
		{
			var i = 0;
			var colorinstance = document.getElementById('color_' + colorid);
			var updated_array = Array();

			while(i < multiple_array.length)
			{
				if(colorid != i)
				{
					updated_array[i] = multiple_array[i];
				}

				++i;

			}

			multiple_array = updated_array;
			multiple_generate();
		}
		function multiple_generate()
		{
			var html = "";

			if(multiple_array.length)
			{
				html = html + "<table>";

				for(var i = 0; i < multiple_array.length; ++i)
				{
					html = html + "<tr>";
					html = html + "<td class=\"bin\"><strong>Color #" + (i + 1) + ":</strong></td>";
					html = html + "<td>";
					html = html + "<input type=\"text\" id=\"color_" + i + "\" name=\"color_multiple[]\" onblur=\"multiple_modify('" + i + "', this.value);\" value=\"" + multiple_array[i] + "\" /> ";
					html = html + "<span class=\"notice\">RGB Value; Split with commas</span>";

					if(i == (multiple_array.length - 1))
					{
						html = html + "<a href=\"javascript:void(0);\" onclick=\"multiple_delete(" + i + ");\">(X)</a>";
					}

					html = html + "</td>";
					html = html + "</tr>";
				}

				html = html + "</table>";
			}

			document.getElementById('multiplecolors').innerHTML = html;
		}
		// -->
		</script>

		<style type="text/css">
		<!--
		* { color: #444444; font: 8pt Verdana, Arial, Sans-serif; }
		a { color: #0088E4; margin-left: 50px; text-decoration: underline; }
		h1 { background-color: #F1F7F7; font-size: 10pt; }
		h1, .container { margin: 50px 50px 0px 50px; padding: 10px; }
		input { background-color: #FFFFFF; border: 1px solid #AAAAAA; height: 20px; padding: 3px; }
		.container { margin-top: 0px; }
		.container h2 { font-size: 9pt; margin: 0px 0px 20px 0px; }
		.container strong { font-weight: bold; }
		.container table { margin-left: 50px; width: 60%; }
		.container td { background-color: #F1F7F7; padding: 7px; }
		.container td.bin { width: 30%; }
		.container td span.notice { font-size: 7pt; }
		.submit { float: right; }
		.submit input { color: #0088E4; padding: 2px 0px; }
		// -->
		</style>
	</head>
	<body>
		<form action="./gradientgd.box.php?do=make" method="post">
			<h1>Gradient Generator</h1>
			<div class="container">
				<h2>Dimensions</h2>
				<table>
					<tr>
						<td class="bin">
							<strong>Height:</strong></td>
						<td>
							<input type="text" name="size_height" value="100" />
							<span class="notice">Pixels</span></td>
					</tr>
					<tr>
						<td class="bin">
							<strong>Width:</strong></td>
						<td>
							<input type="text" name="size_width" value="100" />
							<span class="notice">Pixels</span></td>
					</tr>
				</table>

				<br />
				<h2>Colors</h2>
				<table>
					<tr>
						<td class="bin">
							<strong>Start Color:</strong></td>
						<td>
							<input type="text" name="color_start" value="0,0,0" />
							<span class="notice">RGB Value; Split with commas</span></td>
					</tr>
					<tr>
						<td class="bin">
							<strong>End Color:</strong></td>
						<td>
							<input type="text" name="color_end" value="255,255,255" />
							<span class="notice">RGB Value; Split with commas</span></td>
					</tr>
				</table>

				<br />

				<h2>Multple Color Fade</h2>
				<div id="multiplecolors"></div>
				<a href="javascript:void(0);" onclick="multiple_new('0,0,0');">
					New Color</a>

				<br />
				<div class="submit">
					<input type="submit" value=" Generate " />
				</div>
			</div>
		</form>
<!--
<pre style="font: 11px Monaco Courier, Monospace;"><?php var_dump(unserialize($_SESSION['postcode'])); ?></pre>
-->
	</body>
<?php
		echo("</html>");
	}
?>
Return current item: GD Gradient Generator