#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2021/10/02 01:26:57 +0900> """ Joint image. Windows10 x64 21H1 + Python 3.9.5 64bit + Pillow 8.3.2 """ from PIL import Image, ImageFilter import glob inputfiles = "out/*.png" output = "output.png" xloop = 8 l = sorted(glob.glob(inputfiles)) w, h = 0, 0 imgs = [] for s in l: im = Image.open(s) if im.size[0] > w: w = im.size[0] if im.size[1] > h: h = im.size[1] imgs.append(im) yloop = len(l) // xloop if len(l) % xloop != 0: yloop += 1 tw = w * xloop th = h * yloop nim = Image.new("RGBA", (tw, th), (0, 0, 0, 0)) xi, yi = 0, 0 idx = 0 while yi < yloop: x, y = xi * w, yi * h nim.paste(imgs[idx].copy(), (x, y)) idx += 1 if idx >= len(l): break xi += 1 if xi >= xloop: xi = 0 yi += 1 nim.save(output)