Created
January 30, 2024 02:33
-
-
Save shuax/4cc1d42bfb9f3ee886ff5ebfa3c95c55 to your computer and use it in GitHub Desktop.
This file contains 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
from pathlib import Path | |
from natsort import natsorted | |
from PIL import Image | |
folder = Path("sheep") | |
files = [] | |
for file_path in folder.glob("*.png"): | |
if file_path.is_file(): | |
files.append(file_path) | |
files = reversed(natsorted(files)) | |
# print(files) | |
n = 36 | |
merged_image = Image.new("RGBA", (1296 // n * 44, n * 25)) | |
x = 0 | |
y = 0 | |
for file in files: | |
image = Image.open(file) | |
merged_image.paste(image, (x, y)) | |
x += 44 | |
if x >= 1296 / n * 44: | |
y += 25 | |
x = 0 | |
merged_image.save("merged_image.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment