PHP: Advanced GD // title
PHP: Main
Take a look at this if you havent already; PHP: Starting with GD.
Now onto the tutorial, first things first is that we need to set up the basic GD 'template',
header("Content-type: image/png");
$image = imagecreate(150, 150);
imagepng($image);
imagedestroy($image);
?>
when drawing in GD(with imageline) you need to set a style or it will look really ugly :P
so to do this we use the imagesetstyle function.
the imagesetstyle function requires only two things, the resource link($image) and an array of colors, heres a basic example:
header("Content-type: image/png");
$image = imagecreate(150, 150);
$a = imagecolorallocate($image, 255, 255, 255);
$b = imagecolorallocate($image, 239, 239, 239);
$c = imagecolorallocate($image, 223, 223, 223);
$d = imagecolorallocate($image, 207, 207, 207);
$colors = array($a, $a, $b, $c, $d, $d, $d, $d, $d, $c, $b, $a, $a);
imagesetstyle($image, $colors);
imagepng($image);
imagedestroy($image);
?>
So now the style is set but nothing is happening because we haven't drawn anything.
So now, with imageline() we will draw a couple lines.
header("Content-type: image/png");
$image = imagecreate(150, 150);
$a = imagecolorallocate($image, 255, 255, 255);
$b = imagecolorallocate($image, 239, 239, 239);
$c = imagecolorallocate($image, 223, 223, 223);
$d = imagecolorallocate($image, 207, 207, 207);
$colors = array($a, $a, $b, $c, $d, $d, $d, $d, $d, $c, $b, $a, $a);
imagesetstyle($image, $colors);
imageline($image, 50, 0, 50, 150, IMG_COLOR_STYLED);
imagepng($image);
imagedestroy($image);
?>
okay, so the IMG_COLOR_STYLED means that its drawing the line with the set style.
we put that there instead of the color.
So now that example outputs this:
http://www.bellybuttontreasure.com/GD/style1.php
which as you can see is just a dashed line.
but if you were to open the image up in paint and viewed it you'd see that its the colors we assigned in the
a, a, b, c, d, d, d, d, d, c, b, a, a
format.