note 76037 added to function.imagerectangle
| From: | rogier at osu1 dot php dot net | Date: | Wed, 27 Jun 2007 12:27:43 +0000 |
| Subject: | note 76037 added to function.imagerectangle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128023@lists.php.net to get a copy of this message | ||
In addition to Corey's note, this is the kind of code he means. Note that I always draw an
outer grid border, so drawing lines will always take
1 + ceil((rows+cols)/2) actions. For a 20X20 grid, this means 21 actions, a 10X25 grid takes 19
Actions
<?php
function draw_grid(&$img, $x0, $y0, $width, $height, $cols, $rows, $color) {
//draw outer border
imagerectangle($img, $x0, $y0, $x0+$width*$cols, $y0+$height*$rows, $color);
//first draw horizontal
$x1 = $x0;
$x2 = $x0 + $cols*$width;
for ($n=0; $n<ceil($rows/2); $n++) {
$y1 = $y0 + 2*$n*$height;
$y2 = $y0 + (2*$n+1)*$height;
imagerectangle($img, $x1,$y1,$x2,$y2, $color);
}
//then draw vertical
$y1 = $y0;
$y2 = $y0 + $rows*$height;
for ($n=0; $n<ceil($cols/2); $n++) {
$x1 = $x0 + 2*$n*$width;
$x2 = $x0 + (2*$n+1)*$width;
imagerectangle($img, $x1,$y1,$x2,$y2, $color);
}
}
//example
$img = imagecreatetruecolor(300, 200);
$red = imagecolorallocate($img, 255, 0, 0);
draw_grid($img, 0,0,15,20,20,10,$red);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
have fun ;)
----
Server IP: 194.109.193.76
Probable Submitter: 62.45.207.84
----
Manual Page -- http://www.php.net/manual/en/function.imagerectangle.php
Edit -- https://master.php.net/note/edit/76037
Del: integrated -- https://master.php.net/note/delete/76037/integrated
Del: useless -- https://master.php.net/note/delete/76037/useless
Del: bad code -- https://master.php.net/note/delete/76037/bad+code
Del: spam -- https://master.php.net/note/delete/76037/spam
Del: non-english -- https://master.php.net/note/delete/76037/non-english
Del: in docs -- https://master.php.net/note/delete/76037/in+docs
Del: other reasons-- https://master.php.net/note/delete/76037
Reject -- https://master.php.net/note/reject/76037
Search -- https://master.php.net/manage/user-notes.php