Jun-06-2018, 11:41 AM
I will split the script in 3 different steps:
For the 1st point you can do something like:
- A function that from a list of images create a thumbnail
- List all the image files
- Split in groups of a desired size a list of images
For the 1st point you can do something like:
def create_collage(files, out): # You can add a check to guarantee that the list of images is not bigger than 64... target_img = Image.new("RGB", (800, 800)) for k, png in enumerate(files): row, col = divmod(k, 8) img = Image.open(png) img.thumbnail((100, 100)) target_img.paste(img, (100*row, 100*col)) target_img.save(out)To list all the images in a directory you can use the glob module that will filter them by extension for you:
import glob files = glob.glob('./*.png')And to group every 64 elements might be:
groups = [files[k:k+64] for k in range(0, len(files), 64)]