All pastes #28422 Raw Edit

Miscellany

public php v1 · immutable
#28422 ·published 2005-11-11 23:35 UTC
rendered paste body
function image_gradient($size_y, $start_color, $end_color, $newfilename = null){	if (isset($start_color) && isset($end_color))	{		$this->image_create(1, $size_y);					if ($this->image)		{			$start_color = array("red" => base_convert(substr(ltrim(trim($start_color), "#"), 0, 2), 16, 10), "green" => base_convert(substr($start_color, 2, 2), 16, 10), "blue" => base_convert(substr($start_color, 4, 2), 16, 10));			$end_color = array("red" => base_convert(substr(ltrim(trim($end_color), "#"), 0, 2), 16, 10), "green" => base_convert(substr($end_color, 2, 2), 16, 10), "blue" => base_convert(substr($end_color, 4, 2), 16, 10));							for ($y = 0; $y < imagesy($this->image); $y++)			{				if ($start_color['red'] < $end_color['red'])					$start_color['red']++;											if ($start_color['green'] < $end_color['green'])					$start_color['green']++;										if ($start_color['blue'] < $end_color['blue'])					$start_color['blue']++;									$color = imagecolorallocate($this->image, $start_color['red'], $start_color['green'], $start_color['blue']);				imagesetpixel($this->image, 1, $y, $color);			}							if ($newfilename)			{				if (substr(-4, 4) == '.png')				{					imagepng($this->image, $newfilename);				}				else				{					$newfilename = "{$newfilename}.png";					imagepng($this->image, $newfilename);				}			}			else			{				$newfilename = time().'.png';				imagepng($this->image, $newfilename);			}						return $newfilename;		}		else		{			return false;		}	}	else	{		return false;	}}