[go: up one dir, main page]

Menu

[r1]: / omgm / dev / tilecutter.php  Maximize  Restore  History

Download this file

94 lines (62 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
include "../gm.php";
$zoom = 13;
$sw = "67.8535266,20.2253683";
$ne = "67.8999428,20.2944176";
$srcFile = "out.png";
$srcIm = imagecreatefrompng($srcFile);
$iw = imagesx($srcIm);
$ih = imagesy($srcIm);
echo "Source file Dimensions: Width: ".$iw." Height: ".$ih."\n";
$ims = myCreateImage($iw,$ih);
imagecopy($ims, $srcIm, 0,0, 0,0, $iw,$ih);
imagedestroy($srcIm);
imagepng($ims, "imagetiles2/ims.png");
$box = array();
list($south, $west) = split(",", $sw);
$d1 = Google_RelPix($south, $west, $zoom);
$box[] = $south;
$box[] = $west;
list($north, $east) = split(",", $ne);
$d2 = Google_RelPix($north, $east, $zoom);
$box[] = $north;
$box[] = $east;
list($top, $left) = Google_RelPix($north, $west, $zoom);
$ht = abs( $d1[0] - $d2[0] );
$wd = abs( $d1[1] - $d2[1] );
$im = myCreateImage($wd, $ht, false);
echo "Source transp: ".imagecolortransparent($ims)."\n";
echo "Before Resampl transp: ".imagecolortransparent($im)."\n";
imagecopyresampled($im, $ims, 0,0, 0,0, $wd, $ht, $iw, $ih);
echo "After Resampl transp: ".imagecolortransparent($im)."\n";
imagepng($im, "imagetiles2/im.png");
echo "Map dimension: $wd, $ht\n";
$tiles = Google_Tiles($south, $west, $north, $east, $zoom);
$count = 0;
print_r( imagecolorsforindex($im, imagecolorat($im, 376,370) ));
print_r( imagecolorsforindex($im, imagecolorat($im, 401,370) ));
for($i = 0; $i < count($tiles); $i++){
$tile = $tiles[$i];
$count++;
$fileName = "x".$tile["NAMEX"]."_y".$tile["NAMEY"].".png";
echo "Produce tile $fileName\n";
$imx = myCreateImage(256,256, true);
imagecopy( $imx, $im, 0,0, $tile["PXW"] - $left, $tile["PYN"] - $top, 256,256);
//print_r( imagecolorsforindex($imx, imagecolorat($imx, 186,246) ));
//print_r (imagecolorsforindex($imx, imagecolorat($imx, 251,246) ));
imagepng($imx, "imagetiles2/$zoom/".$fileName);
imagedestroy($imx);
}
imagedestroy($im);
imagedestroy($ims);
echo "Total Tiles produced: $count\n";
function myCreateImage($w, $h, $alphaBlend = true){
$newim = imagecreatetruecolor($w, $h);
imagealphablending($newim, $alphaBlend);
imagesavealpha($newim, !$alphaBlend);
$trans_color = imagecolorallocatealpha($newim, 0,0,0,127);
imagefill($newim, 0,0, $trans_color);
imagecolortransparent($newim, $trans_color);
return $newim;
}
?>