| from PIL import Image |
|
|
|
|
| def stack_images(image_paths, output_path): |
| |
| images = [Image.open(path) for path in image_paths] |
|
|
| |
| width, height = images[0].size |
|
|
| |
| total_width = width * 2 |
| total_height = height * 3 |
| new_image = Image.new("RGB", (total_width, total_height)) |
|
|
| |
| for i, image in enumerate(images): |
| |
| x_offset = (i % 2) * width |
| y_offset = (i // 2) * height |
| new_image.paste(image, (x_offset, y_offset)) |
|
|
| |
| new_image.save(output_path) |
|
|
|
|
| |
| image_paths = [ |
| "/Users/mav/Desktop/example1.png", |
| "/Users/mav/Desktop/image-1.webp", |
| "/Users/mav/Desktop/example2.png", |
| "/Users/mav/Desktop/image-2.webp", |
| "/Users/mav/Desktop/example3.png", |
| "/Users/mav/Desktop/image-3.webp", |
| ] |
| output_path = "stacked_images.jpg" |
| stack_images(image_paths, output_path) |
|
|