Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # dynmapconkitty.py
- # "This script creates a dynmap like rendered top view from
- # flat dynmap data. It ignores all files starting with z (zoomed files)
- # and saves the final result as "full.jpg". The script works with relative
- # paths, so minor adjustments may be required, depending on your needs.
- # Feel free to do whatever you want with it." - Teddy
- #
- # P.S. and TL;DR
- # Run this script from your flat/ directory
- # Written for Python 3.7.1
- import os, operator
- from PIL import Image, ImageOps
- # List of tuples of image data, like (path, x, y)
- images = []
- # Preprocess image data
- for dir in os.listdir("."):
- # Skip files
- if not os.path.isdir(dir):
- continue
- # Get image data by its name
- for image_name in os.listdir(dir):
- # Skip zoomed tiles
- if image_name.startswith("z"):
- continue
- # Get X and Y from basename
- basename = os.path.splitext(image_name)[0]
- x, y = tuple(int(i) for i in basename.split("_"))
- path = os.path.join(dir, image_name)
- images.append((path, x, y))
- # Sort by X, ascending. Get min and max values
- images.sort(key=operator.itemgetter(1))
- min_x, max_x = images[0][1], images[-1][1]
- diff_x = max_x - min_x
- offset_x = abs(min_x) * 128
- # Sort by Y, ascending. Get min and max values
- images.sort(key=operator.itemgetter(2))
- min_y, max_y = images[0][2], images[-1][2]
- diff_y = max_y - min_y
- offset_y = abs(min_y) * 128
- # Create, concat and save image
- output_image = Image.new("RGB", (diff_x * 128, diff_y * 128))
- for (path, x, y) in images:
- image = ImageOps.flip(Image.open(path))
- output_image.paste(image, (offset_x + x*128, offset_y + y*128))
- output_image.save("full.jpg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement