from PIL import Image
import os

# Get list of PNG files in the current directory
image_files = [f for f in os.listdir() if f.lower().endswith('.png')]

# Load all images
images = [Image.open(img) for img in image_files]

# Check if any images exist
if not images:
    raise ValueError("No PNG files found.")

# Calculate total width and maximum height
total_width = sum(img.width for img in images)
max_height = max(img.height for img in images)

# Create a new blank image
combined_image = Image.new('RGBA', (total_width, max_height))

# Paste each image horizontally
x_offset = 0
for img in images:
    combined_image.paste(img, (x_offset, 0))
    x_offset += img.width

# Save final result
combined_image.save('combined_horizontal.png')
print("Image combined and saved as 'combined_horizontal.png'")