Skip to content

Instantly share code, notes, and snippets.

@dvonlehman
Last active December 24, 2015 19:19
Show Gist options
  • Save dvonlehman/6849392 to your computer and use it in GitHub Desktop.
Save dvonlehman/6849392 to your computer and use it in GitHub Desktop.
from PIL import Image
import math
import glob
width, height = [165, 254]
files = glob.glob('./photos/*.jpg')
num_columns = 5
canvas_width = num_columns * width
canvas_height = int(math.ceil(len(files) / float(num_columns))) * height
new_image = Image.new("RGB", (canvas_width, canvas_height), "white")
for i, path in enumerate(files):
pic = Image.open(path)
row = int(math.floor(i / num_columns))
col = i - row * num_columns
print "pasting image %s at %i, %i" % (path, row, col)
new_image.paste(pic, (width * col, height * row))
new_image.save('./combined.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment