3 # WARNING: Doing this for zoom level 0 requires 90 GB of space in $TEMP!
4 # That's why layers 0-2 are not generated by default (you need to change
7 # URL is: /zoom/X/Y.png
8 $srcpath = '/mnt/tiles/lowzoomtilegen/';
9 $dstpath='/mnt/tiles/statictiles/mergedtiles/';
13 # No need to change this usually
25 my $dstfilename = sprintf("%s/%d/%d/%d.png", $dstpath, $ZS, $XS, $YS);
26 my $olfilename = sprintf("%s/%d/%d/%d.png", $srcpath, $ZS, $XS, $YS);
27 if ($ZS >= $ZOOMMAX) {
28 print("Sorry - can only merge Z <= $ZOOMMAX\n"); exit(1);
31 while ($ZS < $ZOOMMAX) {
32 $N = $N * 2; # Twice as many tiles (per direction)
33 $XS = $XS * 2; # Starting at 2*X
34 $YS = $YS * 2; # and 2*Y.
37 printf("Combining %d tiles (%d x %d pixels)\n", $N * $N, $N * $TILESIZE, $N * $TILESIZE);
38 # Now load them all and fill them into one big picture.
39 my $dimage = Graphics::Magick->new('size' => sprintf("%dx%d", $N * $TILESIZE, $N * $TILESIZE)); # magick => 'png',
40 $status = $dimage->Read("xc:white"); # This actually creates the image, the above does NOT - very intuitive!
41 warn "$status" if "$status";
43 for ($x = 0; $x < $N; $x++) {
44 for ($y = 0; $y < $N; $y++) {
45 my $fn = sprintf("%s/%d/%d/%d.png", $srcpath, $ZOOMMAX, $XS + $x, $YS + $y);
46 #print("Loading: $fn\n");
47 my $tmpimg = Graphics::Magick->new();
48 $status = $tmpimg->Read($fn);
49 warn "$status" if "$status";
50 $dimage->Composite( 'image' => $tmpimg, 'compose' => 'over',
51 'x' => ($x * $TILESIZE),
52 'y' => ($y * $TILESIZE));
55 $dimage->Resize('geometry' => sprintf("%dx%d", $TILESIZE, $TILESIZE), 'filter' => 'Lanczos');
56 #print("Loading: $olfilename\n");
57 my $olimg = Graphics::Magick->new();
58 $status = $olimg->Read($olfilename);
59 warn "$status" if "$status";
60 $dimage->Composite( 'image' => $olimg, 'compose' => 'over', 'x' => 0, 'y' => 0 );
61 print("Writing combined image to: $dstfilename\n");
62 $status = $dimage->Write($dstfilename);
63 warn "$status" if "$status";
72 #mergetile(5, 16, 10);
73 #mergetile(6, 33, 21);
74 #mergetile(7, 67, 43);
75 #mergetile(8, 135, 87);
76 my $rz; my $rx; my $ry;
77 for ($rz = 3; $rz <= 8; $rz++) {
78 my $ntilesperdir = 2 ** $rz; # Allgemein: 2 ^ Zoomlevel
79 for ($rx = 0; $rx < $ntilesperdir; $rx++) {
80 my $targdir = sprintf("%s/%d/%d", $dstpath, $rz, $rx);
82 print("Trying to create $targdir...");
83 # FIXME: mkdir -p - the zoom level dir might not exist either!
84 if (mkdir($targdir)) {
90 for ($ry = 0; $ry < $ntilesperdir; $ry++) {
91 mergetile($rz, $rx, $ry);
94 $ntilesperdir = $ntilesperdir * 2;