Skip to content

Instantly share code, notes, and snippets.

@alexandru-dinu
Last active April 7, 2021 12:44
Show Gist options
  • Save alexandru-dinu/71fbe82222c88d5d976f65eeb7178c47 to your computer and use it in GitHub Desktop.
Save alexandru-dinu/71fbe82222c88d5d976f65eeb7178c47 to your computer and use it in GitHub Desktop.
from PIL import Image
import sys
from random import shuffle
import os
imgs = [x.strip() for x in open(sys.argv[1])]
r, c = int(sys.argv[2]), int(sys.argv[3])
w, h = Image.open(imgs[0]).size
ww = w // r
hh = h // r
os.makedirs("out")
shuffle(imgs)
for k in range(20):
imgs_ = imgs[k*r*c:(k+1)*(r*c)]
canvas = Image.new('RGB',(w, h))
for i in range(r):
for j in range(c):
im = Image.open(imgs_[i*c + j])
im.thumbnail((ww, hh))
canvas.paste(im, (i*ww, j*hh))
canvas.save("out/out_%d.png" % k)
print(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment