Skip to content
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

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

Closed
Nitaym opened this issue Nov 22, 2016 · 5 comments
Closed

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

Nitaym opened this issue Nov 22, 2016 · 5 comments
Labels
Bug Any unexpected behavior, until confirmed feature. Cool GIF
Projects
Milestone

Comments

@Nitaym
Copy link

Nitaym commented Nov 22, 2016

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"
@wiredfool
Copy link
Member

That one is weird. I've never seen imagemagick's display have a fully transparent window before.

It's going to take some digging, but I'm suspecting that some of the trouble comes from having the first frame not actually cover the entire size of the gif.

@aclark4life aclark4life added Bug Any unexpected behavior, until confirmed feature. Cool labels Jan 8, 2017
@aclark4life aclark4life added this to the Future milestone Jan 8, 2017
@radarhere radarhere added the GIF label Sep 22, 2017
@radarhere
Copy link
Member

radarhere commented Oct 21, 2018

Just to provide simpler code to reproduce the issue -

from PIL import Image
im = Image.open('test.gif')
im.seek(10)
im.save("out.png")

@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to Icebox in Pillow May 11, 2019
@hantaogo
Copy link

hantaogo commented Nov 5, 2019

我有许多图片遇到了这个BUG,希望能早点解决
I meet this BUG too, I hope this bug could be closed soon!

@radarhere
Copy link
Member

#5333 fixed the blue area.
It did create a new problem, extending the circle arcs, but #5391 fixes that.
The black and white background is still there instead of transparency, but we're making progress.

@radarhere
Copy link
Member

This has been resolved by #5557

Pillow automation moved this from Icebox to Closed Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. Cool GIF
Projects
Pillow
  
Closed
Development

No branches or pull requests

5 participants