So I have 2 images that I would like to display on top of each other. The image on top should have transparency so that the one on the bottom is visible.
Here is my
Try this
from PIL import Image, ImageTk
from Tkinter import Tk, Label
root = Tk()
def RBGAImage(path):
return Image.open(path).convert("RGBA")
face = RBGAImage("faces/face.gif")
eyes = RBGAImage("faces/eyes1.png")
face.paste(eyes, (0, 0), eyes)
facepic = ImageTk.PhotoImage(face)
label1 = Label(image=facepic)
label1.grid(row = 0, column = 0)
root.mainloop()
I do not have both your source images, so I can not be sure it will work with them. Please provide the originals of both if there is any issue.
You can use Image.alpha_composite
to create a new composited image.
from PIL import Image, ImageTk
from Tkinter import Tk, Label
root = Tk()
def RBGAImage(path):
return Image.open(path).convert("RGBA")
face = RBGAImage("faces/face.gif")
eyes = RBGAImage("faces/eyes1.png")
c = Image.alpha_composite(face, eyes)
facepic = ImageTk.PhotoImage(c)
label1 = Label(image=facepic)
label1.grid(row = 0, column = 0)
root.mainloop()