Skip to content

Gif partially lose transparency / misalign, not on all frames #2239

@Nitaym

Description

@Nitaym

I'm building a script to extract a frame from a gif, and encountered a bug (I think).
The script is working properly with several gifs I've tried it on, but this specific gif I'm getting weird misalignments and transparency issues.

This is the original gif
loading

And this is the output from frame 10:
sprite

This happens on almost every frame.

Here's the python code to extract the frame:

with open('loading.gif', "rb") as f:
    gif_data = bytearray(f.read())

try:
    # gif = Image.open(infile)
    gif = Image.open(io.BytesIO(gif_data))
    width, height = gif.size
except IOError as e:
    print "Cant load", gif_data
    sys.exit(1)

mypalette = gif.getpalette()

sprite = Image.new("RGBA", (width, height))
for i in range(10):
    gif.seek(gif.tell() + 1)

gif.putpalette(mypalette)
sprite.paste(gif, (0, 0, width, height))

sprite_data = io.BytesIO()
sprite.save(sprite_data , format='PNG')
sprite_data = sprite_data.getvalue()

with open('sprite.png', 'wb') as f:
    # png_base64 = (json.load(io.BytesIO(converted)))['file']
    # png = base64.b64decode(png_base64)
    f.write(sprite_data)
    print "File written"

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.CoolGIF

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions