56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
|
|
from PIL import Image
|
|||
|
|
import os
|
|||
|
|
import math
|
|||
|
|
|
|||
|
|
Image.MAX_IMAGE_PIXELS = None # Schutz bei großen Bildern deaktivieren
|
|||
|
|
|
|||
|
|
# === KONFIGURATION ===
|
|||
|
|
image_path = "areno_map.png" # Pfad zur großen Karte
|
|||
|
|
output_dir = "tiles" # Zielverzeichnis für die Tiles
|
|||
|
|
tile_size = 256 # Größe eines Tiles
|
|||
|
|
max_zoom = 7 # Zoom-Stufen 0–7
|
|||
|
|
|
|||
|
|
def generate_leaflet_tiles(image_path, output_dir, tile_size=256, max_zoom=7):
|
|||
|
|
original = Image.open(image_path)
|
|||
|
|
orig_width, orig_height = original.size
|
|||
|
|
|
|||
|
|
for z in range(max_zoom + 1):
|
|||
|
|
scale = 2 ** (max_zoom - z)
|
|||
|
|
width = math.ceil(orig_width / scale)
|
|||
|
|
height = math.ceil(orig_height / scale)
|
|||
|
|
|
|||
|
|
# Kein Resize bei maximaler Zoomstufe (Originalgröße)
|
|||
|
|
if z == max_zoom:
|
|||
|
|
resized = original
|
|||
|
|
else:
|
|||
|
|
resized = original.resize((width, height), Image.Resampling.LANCZOS)
|
|||
|
|
|
|||
|
|
tiles_x = math.ceil(width / tile_size)
|
|||
|
|
tiles_y = math.ceil(height / tile_size)
|
|||
|
|
|
|||
|
|
offset_x = tiles_x // 2
|
|||
|
|
offset_y = tiles_y // 2
|
|||
|
|
|
|||
|
|
for x in range(tiles_x):
|
|||
|
|
for y in range(tiles_y):
|
|||
|
|
left = x * tile_size
|
|||
|
|
upper = y * tile_size
|
|||
|
|
right = min(left + tile_size, width)
|
|||
|
|
lower = min(upper + tile_size, height)
|
|||
|
|
|
|||
|
|
tile = resized.crop((left, upper, right, lower))
|
|||
|
|
|
|||
|
|
tile_x = x - offset_x
|
|||
|
|
tile_y = y - offset_y
|
|||
|
|
|
|||
|
|
dir_path = os.path.join(output_dir, str(z), str(tile_x))
|
|||
|
|
os.makedirs(dir_path, exist_ok=True)
|
|||
|
|
tile_path = os.path.join(dir_path, f"{tile_y}.png")
|
|||
|
|
tile.save(tile_path)
|
|||
|
|
|
|||
|
|
print(f"✅ Zoom {z} fertig – {tiles_x}×{tiles_y} Tiles")
|
|||
|
|
|
|||
|
|
print("🎉 Alle Tiles erfolgreich generiert.")
|
|||
|
|
|
|||
|
|
generate_leaflet_tiles(image_path, output_dir, tile_size, max_zoom)
|