Skip to content

Instantly share code, notes, and snippets.

@shuax
Created January 30, 2024 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuax/4cc1d42bfb9f3ee886ff5ebfa3c95c55 to your computer and use it in GitHub Desktop.
Save shuax/4cc1d42bfb9f3ee886ff5ebfa3c95c55 to your computer and use it in GitHub Desktop.
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