Skip to content

Instantly share code, notes, and snippets.

@airalcorn2
Created May 13, 2019 02:32
Show Gist options
  • Select an option

  • Save airalcorn2/39f10de1decf95bdf7b8e6def0cc1588 to your computer and use it in GitHub Desktop.

Select an option

Save airalcorn2/39f10de1decf95bdf7b8e6def0cc1588 to your computer and use it in GitHub Desktop.
import os
from PIL import Image
image_fs = os.listdir()
image_fs.sort()
image_fs = image_fs[:9]
images = map(Image.open, image_fs)
(widths, heights) = zip(*(i.size for i in images))
col_width = min(widths)
row_height = min(heights)
(num_rows, num_cols) = (3, 3)
new_im = Image.new("RGB", (num_cols * col_width, num_rows * row_height))
for (i, image_f) in enumerate(image_fs):
image = Image.open(image_f).resize((col_width, row_height)).rotate(-90)
x_offset = (i % num_cols) * col_width
y_offset = (i // num_cols) * row_height
new_im.paste(image, (x_offset, y_offset))
new_im.save("out.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment