Skip to content

GIF frames loses transparency with Image.alpha_composite() #4650

@hutomosaleh

Description

@hutomosaleh

What did you do?

I am trying to remake a transparent GIF by loading a GIF, extracting the GIF and appending them to make a GIF again.

What did you expect to happen?

The result would retain the transparency.

What actually happened?

The frames loses its transparency when using alpha_composite.

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python: 3.7.4
  • Pillow: 7.0.0

GIF file:
charizard

from PIL import Image

filename = ''
output_png = ''
output_gif = ''
frames = Image.open(filename)
Image.open(filename).convert('RGBA').save(output_png)  # To test that it is indeed transparent per Frame
all_frames = []

for i in range(frames.n_frames):
    frames.seek(i)

    if i != 0:
        curr_frame = frames.convert('RGBA')
        disp_frame = Image.alpha_composite(prev_frames, curr_frame)   # I think the issue is here
    else:
        disp_frame = frames.convert('RGBA')

    all_frames.append(disp_frame)
    prev_frames = frames.convert('RGBA')

all_frames[0].save(output_gif, save_all=True, optimize=True, append_images=all_frames[:], loop=0)

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