Hi, this time I will explain some code to join images together. I will do it through the example of a card game, using the Jupyter notebook.
I have this folder (cdslittle4):
Into this folder I got these files (we've seen it in the last post):
I will create an array with the name of these cards, then I will make a new image file with 3 cards taken casually from all the deck of cards, so that I can visualize them on the same row in Jupyter:
from IPython.core.display import Image, display
num = [str(x) for x in range(1,11)]
num[0] = 'ace'
seeds = ["_of_hearts","_of_clubs","_of_diamonds","_of_spades"]
cdnm = ["img/cdslittle4/"+x+s+".png" for x in num for s in seeds]
e = [Image(x) for x in cdnm]
from random import shuffle
import sys
from PIL import Image as Img
shuffle(e)
def displayall():
for cards in e:
cards.width=50
display(cards)
p1 = e.pop(),e.pop(),e.pop()
new_im = Img.new('RGB', (270,130))
for elem in p1:
for i in range(3):
im=Img.open(p1[i].filename)
new_im.paste(im, (i*90,0))
new_im.save('p1.jpg')
display(Image('p1.jpg'))
# e[0].width=100
# display(e[0])
See ya.
Comments
Post a Comment