Scripts

Gradient in GD (snipper)

Had hem nog liggen, dus waarom niet hierheen. Leuk om achtergronden mee te maken in grafieken (tip*)

gradient-in-gd-snipper
[code]
<?php
$image = imagecreate(200,200);
$achtergrond = imagecolorallocate($image,0,0,255);
function decodeRgbColor($color) {
            if (preg_match('/^\#[0-9a-f]+$/', $color)) {
                $color = substr($color, 1);
                switch (strlen($color)) {
                    case 6:
                        return array(hexdec(substr($color, 0, 2)),
                                     hexdec(substr($color, 2, 2)),
                                     hexdec(substr($color, 4)));
                    case 3:
                        return array(hexdec($color[0] . $color[0]),
                                     hexdec($color[1] . $color[1]),
                hexdec($color[2] . $color[2]));
                case 1:
                return array(hexdec($color[0] . $color[0]),
                hexdec($color[0] . $color[0]),
            	hexdec($color[0] . $color[0]));
            default:
        	return array(0, 0, 0);
    	}
    }
	else
	{
    	return array(0, 0, 0);
	}
}

gradient($image,0,0,200,200,decodeRgbColor("#ffffff"),decodeRgbColor("#000000"));



function gradient($image, $x1, $y1, $x2, $y2, $color_start, $color_end,$reverse=0)
{
	if($reverse != 0)
	{
		$color1 = $color_start;
		$color2 = $color_end;
		$color_start = $color2;
		$color_end = $color1;
	}
    $steps = ($y2 - $y1);
    $inc_r = ($color_end[0] - $color_start[0]) / $steps;
    $inc_g = ($color_end[1] - $color_start[1]) / $steps;
    $inc_b = ($color_end[2] - $color_start[2]) / $steps;
            
    $c = $color_start;
    while ($y2 > $y1)
	{
        $c[0] += $inc_r;
        $c[1] += $inc_g;
        $c[2] += $inc_b;
        $cl = imagecolorallocate($image, $c[0], $c[1], $c[2]);
		imageline($image, $x1, $y1, $x2, $y1++, $cl);
	}
}
imagepng($image);
imagedestroy($image);
?>
[/code]

Reacties

0
Nog geen reacties.