Created
May 9, 2016 08:36
-
-
Save DavidKloucek/7c2eadcd33185a4c0cfe625a4c2cfde7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python3 | |
import os, re | |
from datetime import datetime | |
from PIL import Image | |
SOURCE_DIR = 'C:/Users/David/Desktop/smicka/' | |
FINAL_PATH = 'C:/Users/David/Desktop/smicka.png' | |
pattern = re.compile('^[0-9]+\.(png|jpg|jpeg)$') | |
files = [] | |
width = 0 | |
height = 0 | |
start = datetime.now() | |
for f in os.listdir(SOURCE_DIR): | |
if pattern.match(f): | |
img = Image.open(SOURCE_DIR+f) | |
height += img.size[1] | |
width = img.size[0] if width < img.size[0] else width | |
files.append(f) | |
files.sort(key=lambda i: int(i.split('.')[0]), reverse=True) | |
print('Computed dimensions: ', width, 'x', height, '|', 'Images count:', len(files)) | |
largeImg = Image.new('RGB', (width, height), (255, 255, 255)) | |
y = 0 | |
for fn in files: | |
img = Image.open(SOURCE_DIR+fn) | |
largeImg.paste(img, (0, y)) | |
y += img.size[1] | |
largeImg.save(FINAL_PATH) | |
print('Done in '+str(round((datetime.now() - start).total_seconds(), 2))+'s') | |
print('Saved as ', FINAL_PATH) | |
os.system('pause') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment