What causes the artifacts in dynamically created gif?

122 Views Asked by At

I'm dynamically creating a GIF using PIL and I get this artifact at the tip of Charizard's wings https://i.stack.imgur.com/v7Pj9.jpg Below is the code I'm using to create the gif, I thought by pasting a new background to the gif it wouldn't cause this issue but it looks like that isn't doing anything.

        images = []
        length = min(pokemonImage1.n_frames, pokemonImage2.n_frames)
        for frameIndex in range(0, length):
            pokemonImage1.seek(frameIndex)
            pokemonImage2.seek(frameIndex)
            pkmn1 = pokemonImage1.convert("RGBA")
            pkmn2 = pokemonImage2.convert("RGBA")
            imageInMemory = BytesIO()
            new_img = Image.new('RGBA', (800,400), (0, 0, 0, 0))
            new_img.paste(background, (0,0))
            new_img.paste(pkmn1, (600, 100), mask=pkmn1)
            new_img.paste(pkmn2, (100, 300), mask=pkmn2)
            new_img.save(imageInMemory, 'png')
            imageInMemory.name = "gifInMemory_" + str(frameIndex) + ".png"
            images.append(Image.open(imageInMemory))
            
        gifInMemory = BytesIO()
        images[0].save(gifInMemory, "gif", save_all=True, append_images=images[1:], loop=0, optimize=True, duration=20)
        gifInMemory.name = "battle.gif"
        gifInMemory.seek(0)
0

There are 0 best solutions below