<?
//set width, height and grid size of your map
$width = 200;
$height = 200;
$grid_size = 7;
//select how many object will be there on the map
$n = 4;
//set X and Y position for each object
$array[0]['x']=1;
$array[0]['y']=1;
$array[1]['x']=3;
$array[1]['y']=5;
$array[2]['x']=6;
$array[2]['y']=7;
$array[3]['x']=0;
$array[3]['y']=0;
//Create a new image
$image = ImageCreate($width, $height);
//Make 3 new colors, background, grid and block
$bground = ImageColorAllocate($image, 200, 200, 200);
$grid = ImageColorAllocate($image, 100, 100, 100);
$block = ImageColorAllocate($image, 0, 0, 0);
//Fill background with background color.
ImageFill($image, 0, 0, $bground);
//If grid size is not zero, draw grid
if($grid_size)
{
$step = $grid_size;
//Draw horizontal lines
while($step < $height)
{
imageline ($image, 0, $step, $width, $step, $grid);
$step += $grid_size;
}
$step = $grid_size;
//Draw vertical lines
while($step < $width)
{
imageline ($image, $step, 0, $step, $height, $grid);
$step += $grid_size;
}
}
//for each element in array
for($i=0;$i<$n;$i++)
{
//get X and Y position
$x1 = $array[$i]['x'];
$y1 = $array[$i]['y'];
//if grid is larger then 0 then snap to it
if($grid_size)
{
$x1 = $x1 * $grid_size;
$y1 = $y1 * $grid_size;
}
//make thing on mape same size as grid
$x2 = $x1 + $grid_size;
$y2 = $y1 + $grid_size;
//draw it
imagefilledrectangle ($image, $x1,$y1,$x2,$y2, $block);
}
//tell the browser that this file act as an image
header("Content-Type: image/jpeg");
//output the image in jpeg format
ImageJpeg($image);
//free up resources
ImageDestroy($image);
?>
discuss this topic to forum
