Make all the faces into one big image

Having extracted lots and lots of faces from the Tribune photos, I thought I'd combine them in one big image.

In [ ]:
from PIL import Image
import os
from tqdm import tqdm_notebook

One big image

In [ ]:
# Image dimensions and row length are determined by the number of images
im = Image.new('RGB',(23400, 23450))
row_size = 480
y = 0
x = 0
for index, face in enumerate(tqdm_notebook([f for f in os.listdir('faces') if f[-4:] == '.jpg']), start=1):
    face_img = Image.open(os.path.join('faces', face))
    face_img.thumbnail((50, 50))
    try:
        im.paste(face_img, (x, y, x+50, y+50))
    except ValueError:
        print(face)
    if (index % row_size) == 0:
        x = 0
        y += 50
    else:
        x += 50
im.save('faces.jpg')

Lots of big images for printing

Creates A3/A4 sized images for easy printing. Perfect for a pop-up exhibition!

In [ ]:
# Image dimensions and row length are determined by the number of images
# 595 x 842 pixels
# 3480 on A4 - 70 x 49
# 230,677 images
cols = 70
rows = 49
# cols = 16
# rows = 11
faces_per_page = cols * rows
number_of_pages = int(230677 / faces_per_page)

faces = [f for f in os.listdir('faces') if f[-4:] == '.jpg']
for page in range(0, number_of_pages):
    y = 0
    x = 0
    im = Image.new('RGB', (cols*50, rows*50), 'white')
    start = page * faces_per_page
    for index, face in enumerate(tqdm_notebook(faces[start:start+faces_per_page]), start=1):
        face_img = Image.open(os.path.join('faces', face))
        face_img.thumbnail((50, 50))
        try:
            im.paste(face_img, (x, y, x+50, y+50))
        except ValueError:
            print(face)
        if (index % cols) == 0:
            x = 0
            y += 50
        else:
            x += 50
    im.save('faces-{}.jpg'.format(page))