Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Created March 8, 2017 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubershmekel/932e88ddf67aa3b209717b6fb19af389 to your computer and use it in GitHub Desktop.
Save ubershmekel/932e88ddf67aa3b209717b6fb19af389 to your computer and use it in GitHub Desktop.
Pile of images positioned randomly
import glob
import random
from PIL import Image
from tqdm import tqdm
images = glob.glob('pngs2/*.png')
width = 700
height = 700
margin = 50
canvas = Image.new("RGBA", (width, height))
for image_fname in tqdm(images):
img = Image.open(image_fname)
if img.mode != "RGBA":
img = img.convert("RGBA")
#angle = random.randint(-45, 45)
#rotated = img.rotate(angle, expand=True)
position = random.randint(0, width - margin), random.randint(0, height - margin)
canvas.paste(img, position, img)
#canvas.paste(rotated, position, rotated)
canvas.save("pile.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment