I'm trying to put 3 images inside a background image with random coordinates, using the Python Imaging Library (PIL). I have attached all the necessary images just below the code.
#background = 800x400
#red,blue,green = 120x48
background = Image.open('background.png')
red = Image.open('red.png')
blue = Image.open('blue.png')
green = Image.open('green.png')
positionxred = random.randint(0, 800)
positionyred = random.randint(0, 400)
positionxblue = random.randint(0, 800)
positionyblue = random.randint(0, 400)
positionxgreen = random.randint(0, 800)
positionygreen = random.randint(0, 400)
background.paste(red, (positionxred, positionyred), red)
background.paste(blue, (positionxblue, positionyblue), blue)
background.paste(green, (positionxgreen, positionygreen), green)
background.save("test.png")
Attachments:
background
red
blue
green
test
my goal is that the area coordinates of the red, blue, green images are not the same, because if they are, the images will stay on top of each other as shown in the attached test image.
As you can see, the size of the images red, blue and green are 120x48, that is, 5760 units of area.
The background image has 400x800, with a total of 320000 units of area.
I need a way that the 5760 area units of each image do not stay on top of the other image, using some looping command, how should I proceed?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…