$link = mysql_connect("localhost", "root", "");
mysql_select_db("places");
function getpost($postcode)
{
$char = 1;
do {
$part = substr($postcode, 0, $char);
$result = mysql_query("SELECT * FROM codes WHERE post LIKE '$part%'");
$rows = mysql_num_rows($result);
++$char;
}
while ($rows > 1);
$results = mysql_fetch_array($result, MYSQL_ASSOC);
return $results['post'];
}
$post = getpost($_GET['postcode']);
$postcode = $post;
$sql = "SELECT * FROM codes WHERE post='$postcode'";
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
$latitude = $row[5];
$longitude = $row[6];
settype($latitude, "float");
settype($longitude, "float");
$longwidth = (10.40480+1.76791); // 12.17271
$latheight = (58.67925-49.97763);//8.70162
$canvaswidth = 381;
$canvasheight = 440;
$amountleft = (((10.40480+$longitude)/$longwidth)*$canvaswidth);
$amountdown = ($canvasheight-(((($latitude-49.97763)/$latheight))*$canvasheight));
$amountleft = round($amountleft);
$amountdown = round($amountdown);
$image = imagecreatefrompng("croppedmap.png");
$red = imagecolorallocate($image, 255,0,0);
imagefilledrectangle($image,$amountleft-2,$amountdown-2,$amountleft+2,$amountdown+2,$red);
header ("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>