The below code makes more sense (calculations up top, image generation below)....
<?PHP
$source = "stella|00:0F:B3:FF:58:0A|Actiontec|0%|Open|WEP|802.11g|9|N 42.2504633|W 71.8319700|1 2 5.5 11|0 6 9 12 18 24 36 48 54|10-04-2007 11:37:41 393|10-04-2007 11:37:41 393|Infrastructure|Unknown|26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26-26";
$return = file($source);
$X = 20;
$wifissid = explode ("|", $return[0], 17);
$sgn= $wifissid[16];
$signal = explode("-", $sgn);
$count = count($signal);
if ( 640 < $count)
{
$Width=640;
$Height=480;
$wid=$Width+$count;
}
else
{
$wid=640;
$Height=480;
}
$img = ImageCreateTrueColor($wid, $Height);
$bg = imagecolorallocate($img, 255, 255, 255);
$grid = imagecolorallocate($img,0,0,0);
$color = imagecolorallocate($img, 255, 0, 0);
function imagegrid($image, $w, $h, $s, $color)
{
for($iw=0; $iw<$w/$s; $iw++){imageline($image, $iw*$s, 1, $iw*$s, $w, $color);}
for($ih=0; $ih<$h/$s; $ih++){imageline($image, 1, $ih*$s, $w, $ih*$s, $color);}
}
foreach($signal as $sig)
{
imageline($img, $X ,460, $X, 460-($sig*4), $color);
$X++;
imageline($img, $X ,460, $X, 460-($sig*4), $color);
$X=$X+2;
}
$date=date('mdHis');
imagefill($img,0,0,$bg);
imagesetstyle($img,array($bg,$grid));
imagestring($img, 3, 25, 5, $count, $color);
imagegrid($img,$wid,$Height,19.99,$grid);
Print "You can find your Wifi Graph <a href=\"tmp/$date.png\">Here</a><br>";
Print "<img src=\"tmp/$date.png\">";
ImagePNG($img, "tmp/".$date.".png");
ImageDestroy($img);
?>
Now, what are you trying to do with makegrid()? It does what is expected which is create a grid that is 640 x 480 pixels every time. If you're talking about that "red" area, then that's not in the function, but rather in the foreach($signal as $sig){} loop....
Is that what you're talking about?