Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. # dynmapconkitty.py
  2. # "This script creates a dynmap like rendered top view from
  3. # flat dynmap data. It ignores all files starting with z (zoomed files)
  4. # and saves the final result as "full.jpg". The script works with relative
  5. # paths, so minor adjustments may be required, depending on your needs.
  6. # Feel free to do whatever you want with it." - Teddy
  7. #
  8. # P.S. and TL;DR
  9. # Run this script from your flat/ directory
  10. # Written for Python 3.7.1
  11.  
  12. import os, operator
  13. from PIL import Image, ImageOps
  14.  
  15. # List of tuples of image data, like (path, x, y)
  16. images = []
  17.  
  18. # Preprocess image data
  19. for dir in os.listdir("."):
  20. # Skip files
  21. if not os.path.isdir(dir):
  22. continue
  23. # Get image data by its name
  24. for image_name in os.listdir(dir):
  25. # Skip zoomed tiles
  26. if image_name.startswith("z"):
  27. continue
  28. # Get X and Y from basename
  29. basename = os.path.splitext(image_name)[0]
  30. x, y = tuple(int(i) for i in basename.split("_"))
  31. path = os.path.join(dir, image_name)
  32. images.append((path, x, y))
  33.  
  34. # Sort by X, ascending. Get min and max values
  35. images.sort(key=operator.itemgetter(1))
  36. min_x, max_x = images[0][1], images[-1][1]
  37. diff_x = max_x - min_x
  38. offset_x = abs(min_x) * 128
  39.  
  40. # Sort by Y, ascending. Get min and max values
  41. images.sort(key=operator.itemgetter(2))
  42. min_y, max_y = images[0][2], images[-1][2]
  43. diff_y = max_y - min_y
  44. offset_y = abs(min_y) * 128
  45.  
  46. # Create, concat and save image
  47. output_image = Image.new("RGB", (diff_x * 128, diff_y * 128))
  48. for (path, x, y) in images:
  49. image = ImageOps.flip(Image.open(path))
  50. output_image.paste(image, (offset_x + x*128, offset_y + y*128))
  51. output_image.save("full.jpg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement