note 66902 deleted from function.imageline by bjori
| From: | bjori@php.net | Date: | Thu, 01 Jun 2006 00:51:51 +0000 |
| Subject: | note 66902 deleted from function.imageline by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-112691@lists.php.net to get a copy of this message | ||
Note Submitter: James Logsdon
----
I made a Gradient function that allows you to specify the starting and ending colors to be used.
Here it is:
For an example, you can go to http://www.girsbrain.org/imagegrad.php (source is
at http://www.girsbrain.org/imagegrad.php?source)
<?php
function imageGradient ( $img, $Data = array ( ) )
{
$StartX = !empty ( $Data['StartX'] ) ? $Data['StartX'] : 0;
$StartY = !empty ( $Data['StartY'] ) ? $Data['StartY'] : 0;
$Width = !empty ( $Data['Width'] ) ? $Data['Width'] : imagesx ( $img );
$Height = !empty ( $Data['Height'] ) ? $Data['Height'] : imagesy ( $img );
$Colors = is_array ( $Data['Colors'] ) ? $Data['Colors'] : array (
'Start' => array ( 'Red' => 0, 'Green' => 0, 'Blue'
=> 0 ), 'End' => array ( 'Red' => 255, 'Green' => 255,
'Blue' => 255 ) );
$EndY = $StartY + $Height;
$RedMove = $Colors['End']['Red'] -
$Colors['Start']['Red'];
$RedChange = $RedMove / $Height;
$GreenMove = $Colors['End']['Green'] -
$Colors['Start']['Green'];
$GreenChange = $GreenMove / $Height;
$BlueMove = $Colors['End']['Blue'] -
$Colors['Start']['Blue'];
$BlueChange = $BlueMove / $Height;
$CurRed = $Colors['Start']['Red'];
$CurGreen = $Colors['Start']['Green'];
$CurBlue = $Colors['Start']['Blue'];
for ( $CurY = $StartY; $CurY <= $EndY; $CurY++ )
{
$Color = imagecolorallocate ( $img, round ( $CurRed, 0 ), round ( $CurGreen, 0 ), round (
$CurBlue, 0 ) );
imageline ( $img, $StartX, $CurY, $Width, $CurY, $Color );
$CurRed += $RedChange;
$CurGreen += $GreenChange;
$CurBlue += $BlueChange;
}
}
?>