-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Black background on frames after first frame in GIF using Pillow #5755
Comments
If you simplify your code to just reading and saving your GIF, from PIL import Image, ImageSequence
gif = Image.open("gif4.GIF")
ind = 0
for frame in ImageSequence.Iterator(gif):
frame.save('{}.png'.format(ind))
ind += 1 you will see that the colours are still not correct. I expect this is part of a long standing bug where Pillow doesn't correctly read the colours from different palettes after the first GIF frame. See #3735 for a longer explanation. |
Yes, I am stuck on this for a week now. I on read an issue that this bug has been resolved in 8.1 but I'm still having this problem. Can you suggest any other library of way-out to get this done in Python? |
Pillow 8.4.0 has been released on PyPI. So if you upgrade, this should now work for you. |
I am having this issue on 8.4.0 |
from PIL import Image, ImageSequence, GifImagePlugin
import os
bg = Image.open('images/bg/Background Sky.gif')
body = Image.open('images/body/Body Blue.gif')
eyes = Image.open('images/eyes/Eyes Green.gif')
headwear = Image.open('images/headwear/Headwear Party Hat.gif')
frames = []
for idx, frame in enumerate(ImageSequence.Iterator(bg)):
#frame.paste(ImageSequence.Iterator(bg)[idx], mask=ImageSequence.Iterator(bg)[idx].convert("RGB"))
frame = frame.copy().convert('RGBA')
frame = frame.resize((640,640))
#frame.show()
frame.paste(ImageSequence.Iterator(body)[idx], mask=ImageSequence.Iterator(body)[idx].convert("RGBA"))
frame.paste(ImageSequence.Iterator(eyes)[idx], mask=ImageSequence.Iterator(eyes)[idx].convert("RGBA"))
frame.paste(ImageSequence.Iterator(headwear)[idx], mask=ImageSequence.Iterator(headwear)[idx].convert("RGBA"))
frames.append(frame)
print(frames)
frames[0].save('images/generated/output.gif', save_all=True, append_images=frames[1:], loop=0) |
Please create a new issue and attach the GIFs you are trying to load. |
What did you do?
I am trying to place a gif on png using Pillow. It's giving black background after the first frame. I have tried every solution on Github including #1987 and #1976
What did you expect to happen?
It should make a transparent GIF place on a png.
What actually happened?
Currently, all frames after the first frame are having a black background. The code is working file on small GIFs.
Orignal Gif:
Background Image:
Final Result:
Frames:
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: