from PIL import Image
def merge_images_horizontally(images):
# Assuming all images have the same height
height = images[0].height
total_width = sum(image.width for image in images)
merged_image = Image.new('RGB', (total_width, height))
x_offset = 0
for image in images:
merged_image.paste(image, (x_offset, 0))
x_offset += image.width
return merged_image
# Example usage:
if __name__ == "__main__":
# Replace these file paths with the paths of your images
image_paths = ["image1.jpg", "image2.jpg", "image3.jpg"]
images = [Image.open(path) for path in image_paths]
merged_image = merge_images_horizontally(images)
# Save the merged image
merged_image.save("merged_image.jpg")