List Info

Thread: note 76037 added to function.imagerectangle




note 76037 added to function.imagerectangle
user name
2007-06-27 07:27:43
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  -- h
ttps://master.php.net/note/delete/76037/integrated
Del: useless     -- http
s://master.php.net/note/delete/76037/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/76037/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76037
Reject      -- https://mast
er.php.net/note/reject/76037
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )