// OJW 2006 GNU GPL v2 or later list($S,$N,$W,$E) = array($_GET["S"], $_GET["N"],$_GET["W"],$_GET["E"]); list($Width,$Height) = array($_GET["width"], $_GET["height"]); list($Y1,$Y2) = array(Lat2Y($N), Lat2Y($S)); list($X1,$X2) = array(Long2X($W), Long2X($E)); $dx = $X2 - $X1; $dy = $Y2 - $Y1; if($dx <= 0 || $dy <= 0 || $Width <= 0 || $Height <= 0) exit; if($Width > 1000 || $Height > 1000) exit; $ImageWidth = 256; for($Z = 5; $Z < 17; $Z++){ $Pow2 = pow(2,$Z); $MapWidth = $Pow2 * $ImageWidth; $InputWidth = $dx * $MapWidth; $InputHeight = $dy * $MapWidth; $Ratio1 = $InputWidth / $Width; $Ratio2 = $InputHeight / $Height; $Ratio = min($Ratio1, $Ratio2); if($InputWidth < 2560 && $InputHeight < 2560 && $Ratio >= 1){ $cx = $Pow2 * ($X2 + $X1) / 2.0; $cy = $Pow2 * ($Y2 + $Y1) / 2.0; $icx = floor($cx); $icy = floor($cy); $fcx = $cx - $icx; $fcy = $cy - $icy; $nx = ceil($InputWidth / $ImageWidth); $ny = ceil($InputHeight / $ImageWidth) ; $Image = imagecreatetruecolor($InputWidth, $InputHeight); if($nx * $ny * 4 < 1000){ for($ix = -$nx; $ix <= $nx; $ix++){ for($iy = -$ny; $iy <= $ny; $iy++){ $X = $icx + $ix; $Y = $icy + $iy; if(1) $UrlTemplate = "http://tile.openstreetmap.org/%d/%d/%d.png"; else $UrlTemplate = "http://tah.dev.openstreetmap.org/Tiles/tile/%d/%d/%d.png"; $URL = sprintf( $UrlTemplate, $Z, $X, $Y); $SubImage = imagecreatefrompng($URL); imagecopy( $Image, $SubImage, ($InputWidth / 2) - (($fcx - $ix)* $ImageWidth), ($InputHeight / 2) - (($fcy - $iy) * $ImageWidth), 0, 0, $ImageWidth, $ImageWidth); } } $ImageOutput = imagecreatetruecolor($Width, $Height); imagecopyresampled( $ImageOutput, $Image, 0, 0, 0, 0, $Width, $Height, $InputWidth, $InputHeight); header("Content-type: Image/PNG"); imagepng($ImageOutput); exit; } } } ?>