-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
What did you do?
Actually I have two files. One is a Transparent gif and the second one is a JPG image and my aim is to use image as a background and gif as a foreground. In short, I want to merge them.
What did you expect to happen?
I want an image as a background and gif as a foreground. In short, I want to merge them.
What actually happened?
But using the pillow library is giving me output like this.

What are your OS, Python, and Pillow versions?
- OS: Windows
- Python: Python 3.8.5
- Pillow:
from PIL import Image, ImageSequence
transparent_foreground = Image.open("C:\\Users\\PRATHAMESH\\Desktop\\Python try\\me.jpg")
animated_gif = Image.open("C:\\Users\\PRATHAMESH\\Desktop\\Python try\\celeb (2).gif")
x, y = transparent_foreground.size
frames = []
for frame in ImageSequence.Iterator(animated_gif):
frame = frame.copy()
frame.paste(transparent_foreground,(x,y),mask=transparent_foreground)
frames.append(frame)
frames[0].save('output.gif', save_all=True, append_images=frames[1:])