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

A frame is *ignored* when a GIF is saved with a completely transparent frame included #6785

Closed
hsohliyt105 opened this issue Dec 7, 2022 · 1 comment · Fixed by #6787
Closed
Labels

Comments

@hsohliyt105
Copy link

hsohliyt105 commented Dec 7, 2022

What did you do?

I tried to save a gif file with a completely transparent frame.

What did you expect to happen?

expected

What actually happened?

example
You can see that the last empty frame does not appear. Instead, the duration of the previous frame is delayed.

What are your OS, Python and Pillow versions?

  • OS: I tried both Windows 10, MacOS, and Raspbian
  • Python: 3.10.4
  • Pillow: 9.3.0

Note that I came up with a simple code rather than my original code to keep this simple.

from PIL import Image, ImageDraw

image1 = Image.new("RGBA", (100, 100), "#00000000")
image2 = Image.new("RGBA", (100, 100), "#00000000")
image3 = Image.new("RGBA", (100, 100), "#00000000")

draw = ImageDraw.Draw(image2)
draw.rectangle((25, 25, 75, 75), fill = "#FF0000FF")

image1.save("example.gif", format="GIF", save_all=True, disposal=2, loop=0, duration=1000, append_images=[image2, image3])

This also happens when a completely black (#000000) image is appended, regardless of the transparency.

from PIL import Image, ImageDraw

image1 = Image.new("RGBA", (100, 100), "#00000000")
image2 = Image.new("RGBA", (100, 100), "#00000000")
image3 = Image.new("RGBA", (100, 100), "#00000000")

draw = ImageDraw.Draw(image2)
draw.rectangle((25, 25, 75, 75), fill = "#FF0000FF")

draw = ImageDraw.Draw(image3)
draw.rectangle((25, 25, 75, 75), fill = "#000000FF")

image1.save("example.gif", format="GIF", save_all=True, disposal=2, loop=0, duration=1000, append_images=[image2, image3])

*edit
I checked that "white" (#FFFFFF00) transparent images are normally appended to the image.

Example code:

from PIL import Image, ImageDraw

image1 = Image.new("RGBA", (100, 100), "#FFFFFF00")
image2 = Image.new("RGBA", (100, 100), "#FFFFFF00")
image3 = Image.new("RGBA", (100, 100), "#FFFFFF00")

draw = ImageDraw.Draw(image2)
draw.rectangle((25, 25, 75, 75), fill = "#FF0000FF")

image1.save("example.gif", format="GIF", save_all=True, disposal=2, loop=0, duration=1000, append_images=[image2, image3])

This will produce the wanted result. But anyways, I think this still is an issue.

@radarhere
Copy link
Member

I've created PR #6787 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants