File size: 497 Bytes
3eb1ce9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import math
from typing import List
from PIL import Image
def get_image_grid(images: List[Image.Image]) -> Image:
num_images = len(images)
cols = int(math.ceil(math.sqrt(num_images)))
rows = int(math.ceil(num_images / cols))
width, height = images[0].size
grid_image = Image.new('RGB', (cols * width, rows * height))
for i, img in enumerate(images):
x = i % cols
y = i // cols
grid_image.paste(img, (x * width, y * height))
return grid_image
|