首页 > 解决方案 > 是什么导致动态创建的 gif 中的伪影?

问题描述

我正在使用 PIL 动态创建一个 GIF,我在 Charizard 的翅膀尖端得到了这个神器 https://imgur.com/a/GD9wUwR 下面是我用来创建 gif 的代码,我想通过粘贴一个新的gif的背景它不会导致这个问题,但它看起来没有做任何事情。

        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)

标签: pythonpython-imaging-librarygifimage-manipulationartifact

解决方案


推荐阅读