Skip to content

Instantly share code, notes, and snippets.

@bowlercaptain
Created April 14, 2024 13:43
Show Gist options
  • Save bowlercaptain/74e8e661a279a3909c53cb2e5d5816db to your computer and use it in GitHub Desktop.
Save bowlercaptain/74e8e661a279a3909c53cb2e5d5816db to your computer and use it in GitHub Desktop.
#chatgpt wrote this and then I fixed it. Still slow AF since it didg't believe in the 'all the same resolution' thing I told it.
from PIL import Image
import os
# Specify the folder containing your images
image_folder = ""
# Get a list of image filenames in the folder
image_files = [f for f in os.listdir(image_folder) if f.lower().endswith((".png", ".jpg", ".jpeg"))]
# Initialize the total width and height
total_width = 0
max_height = 0
# Load each image, calculate offset, and update total dimensions
for i, image_file in enumerate(image_files):
image_path = os.path.join(image_folder, image_file)
img = Image.open(image_path)
width, height = img.size
total_width += width
max_height = max(max_height, height)
print("loaded "+str(total_width))
# Create a new blank image with the calculated dimensions
result_image = Image.new("RGB", (total_width, max_height))
# Paste each image onto the result image with the appropriate offset
x_offset = 0
for i, image_file in enumerate(image_files):
img = Image.open(os.path.join(image_folder, image_file))
result_image.paste(img, (x_offset, 0))
x_offset += img.width * i
# Save the final animation strip as a PNG
result_image.save(image_folder + "/output_animation.png")
print(f"Animation strip saved as 'output_animation.png'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment