Create Gradient

<?php

/**
 * create_gradient
 *
 * Create an image that is a color gradient.
 *
 * @version 0.1
 * @author Contributors at eXorithm
 * @link /algorithm/view/create_gradient Listing at eXorithm
 * @link /algorithm/history/create_gradient History at eXorithm
 * @license /home/show/license
 *
 * @param string $start_color (hex color code) The start color of the gradient.
 * @param string $end_color (hex color code) The end color of the gradient.
 * @param number $size The length of the resulting image.
 * @param number $thickness The thickness of the resulting image.
 * @param mixed $orientation The orientation of the gradient.
 * @return resource GD image
 */
function create_gradient($start_color='ffffff',$end_color='000000',$size=100,$thickness=5,$orientation='')
{
	if ($orientation=="vertical") {
		$img=imagecreatetruecolor($thickness,$size);
	} else {
		$img=imagecreatetruecolor($size,$thickness);
	}
	
	$start_r  = hexdec(substr($start_color, 0, 2));
	$start_g  = hexdec(substr($start_color, 2, 2));
	$start_b  = hexdec(substr($start_color, 4, 2));
	
	$end_r  = hexdec(substr($end_color, 0, 2));
	$end_g = hexdec(substr($end_color, 2, 2));
	$end_b = hexdec(substr($end_color, 4, 2));
	
	for ($i=0;$i<$size;$i++) {
		$red = round($start_r - ($start_r-$end_r) * ($i / ($size-1)));
		$green = round($start_g - ($start_g-$end_g) * ($i / ($size-1)));
		$blue = round($start_b - ($start_b-$end_b) * ($i / ($size-1)));
		$color = imagecolorallocate($img, $red, $green, $blue);
		if ($orientation=="vertical") {
			for ($k=0;$k<$thickness;$k++)
				imagesetpixel($img, $k, $i, $color);
		} else {
			for ($k=0;$k<$thickness;$k++)
				imagesetpixel($img, $i, $k, $color);
		}
	}
	
	return  $img;
}

?>