Created
April 8, 2019 23:23
-
-
Save JupyterJones/5359048c40d0909d5017f5e99cdd0795 to your computer and use it in GitHub Desktop.
randomly finds an image in a directory crops it and overlays it on a blank image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from random import randint | |
import randon | |
import os | |
def ol(filenamez,num): | |
body = Image.open(filenamez).convert("RGBA") | |
path = r"/home/jack/Desktop/Images/thegirls/IMGS/" | |
base_image = random.choice([ | |
y for y in os.listdir(path) if y.endswith(".jpg") or y.endswith(".png") | |
if os.path.isfile(os.path.join(path, y)) | |
]) | |
filenamez=(path+base_image) | |
head = Image.open(filenamez).convert("RGBA") | |
w,h = head.size | |
UR=randint(20,w-250) | |
LR= randint(20,h-150) | |
U= randint(25,250) | |
L =randint(25,150) | |
U= randint(25,250) | |
L =randint(25,150) | |
UL = UR +U | |
LL =LR+L | |
headbox= (UR,LR,UL,LL) | |
head.crop(headbox).save("head.png") | |
head_crop = Image.open("head.png") | |
body.paste(head_crop, (UR,LR)) | |
body.save("out2.png") | |
body.save("EXP/"+num+"20out1.png") | |
IM = Image.new('RGBA',(1280,720),(0,0,0,0)) | |
IM.save("out2.png") | |
for n in range(1,400): | |
num = str(n) | |
filenamez = "out2.png" | |
ol(filenamez,num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment