Skip to content

Instantly share code, notes, and snippets.

@Themis3000
Last active March 22, 2020 21:35
Show Gist options
  • Save Themis3000/6c70e83e658143e68655005923b2b01f to your computer and use it in GitHub Desktop.
Save Themis3000/6c70e83e658143e68655005923b2b01f to your computer and use it in GitHub Desktop.
MinedMap image conjoiner. Merges image files generated by MinedMap into 1 big image file
from PIL import Image
import os
# path to file with map pieces
directory = "C:/Users/.../MinedMap-1.15.1.Win64/MinedMap-1.15.1.Win64/map/map/0"
# [1 - 100] modify this value to change the quality of the output image
quality = 95
# [True/False] downscale image
downscale = False
# base width (in pixels) - will not change anything if downscale is disabled
basewidth = 1000
input_image_size = 512
files = os.listdir(directory)
formatted_files = []
for file in files:
file_array = file.split(".")
if len(file_array) == 4:
formatted_files.append([file, int(file_array[1]), int(file_array[2])])
x_min = min(map(lambda x: x[1], formatted_files)) * -1
y_min = min(map(lambda x: x[2], formatted_files)) * -1
x_len = max(map(lambda x: x[1], formatted_files)) + x_min + 1
y_len = max(map(lambda x: x[2], formatted_files)) + y_min + 1
total_files = len(formatted_files)
img_out = Image.new("RGB", (x_len * input_image_size, y_len * input_image_size))
for i, file in enumerate(formatted_files):
print(f"processing file {i+1}/{total_files}")
img = Image.open(f"{directory}/{file[0]}")
x = (file[1] + x_min) * input_image_size
y = (file[2] + y_min) * input_image_size
img_out.paste(img, (x, y, x + input_image_size, y + input_image_size))
if downscale:
print("downscaling...")
wpercent = (basewidth / float(img_out.size[0]))
hsize = int((float(img_out.size[1]) * float(wpercent)))
img_out = img_out.resize((basewidth, hsize), Image.ANTIALIAS)
print("saving...")
img_out.save(os.path.join(os.path.dirname(__file__), 'out.jpg'), quality=quality, optimize=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment