Skip to content

GIF degrading after initial frame when import #5837

@tomhaydn

Description

@tomhaydn

I'm trying to create a programatic assembler for a variety of animated gifs. I want to do this by grabbing each of the parts (each individually animated) and layering them to create the final GIF. All parts apart from the background have transparency.

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 = Image.new('RGBA', (640, 640), color=(255,0,0,0))
    frame.paste(ImageSequence.Iterator(bg)[idx])
    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[0:])
frames[0].save('images/generated/output.gif', save_all=True, append_images=frames[1:], loop=0)

This is the final output:
output

This is the raw background:
Background Sky

I have tried to set the frame to a copy of the frame within the for loop:
frame = frame.copy()

But this fails also.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions