Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import PIL
- import math
- from PIL import Image
- import os
- target_size = 4096
- new_image = Image.new("RGBA", (target_size, target_size), None)
- x = 1
- y = 1
- def get_path():
- path = "images/"
- return path
- images = []
- for path, dirs, files in os.walk(get_path()):
- for file_name in files:
- images.append(path + file_name)
- images.sort(key=os.path.getmtime, reverse=False)
- progress = 1
- for image in images:
- side = round(math.sqrt(len(files))) + 2
- cell_size = int((target_size / int(side)) * 1.0)
- im = Image.open(image, "r")
- bbox = im.getbbox()
- x_size = bbox[2]
- y_size = bbox[3]
- multi = 1.0 / float(cell_size)
- scaler = float(y_size) * multi
- y_target = cell_size
- x_target = int(x_size / scaler)
- im = im.convert("RGB")
- im2 = im.resize((x_target, y_target), Image.ANTIALIAS)
- im3 =im.resize((640, 480), Image.ANTIALIAS)
- im3.save("export/progress_{}.png".format(progress), "PNG")
- progress += 1
- if x + x_target < target_size:
- new_image.paste(im2, (x, y))
- x += x_target
- else:
- y += cell_size
- x = 1
- new_image.paste(im2, (x, y))
- x += x_target
- new_image.save("export/montage_output.png", "PNG")
- print ("finished")
Advertisement
Add Comment
Please, Sign In to add comment