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

Animated GIFs in Safari #8072

Closed
kamenik opened this issue May 21, 2024 · 2 comments
Closed

Animated GIFs in Safari #8072

kamenik opened this issue May 21, 2024 · 2 comments
Labels

Comments

@kamenik
Copy link

kamenik commented May 21, 2024

This code generates simple animation, it looks well in chrome/firefox but it has broken background if shown in Safari. I am not able to tell, if it is problem of Pillow or Safari, could you loot at it please?

from io import BytesIO

from PIL import Image, ImageDraw, GifImagePlugin
from PIL.Image import Image as TImage

images = []

for i in range(1, 100):
    img = Image.new('RGBA', (500, 500))
    draw = ImageDraw.Draw(img)

    draw.rectangle((0, 0, 500, 500), fill=(0, 0, 64))
    draw.rectangle((100, 200 - (4 * i % 100), 400, 400), fill=(255, 255, 255))

    draw.rectangle((4 * i, 4 * i, 4 * i + 100, 4 * i + 100), fill=(255, 128, 0))

    img = img.convert("RGB")

    images.append(img)

img_io = BytesIO()

images[0].save(img_io, format="gif", save_all=True, append_images=images[1:], optimize=False, loop=0)
img_io.seek(0)
raw_bytes = img_io.getvalue()

with open('animgif.gif', 'wb') as f:
    f.write(raw_bytes)
OS: latest OpenSUSE Tumbleweed

Report:
--------------------------------------------------------------------
Pillow 10.3.0
Python 3.11.9 (main, Apr 08 2024, 06:18:15) [GCC]
--------------------------------------------------------------------
Python executable is /home/.../venv/bin/python
Environment Python files loaded from /home/.../venv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/.../venv/lib64/python3.11/site-packages/PIL
Binary Pillow modules loaded from /home/.../lib64/python3.11/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.14, harfbuzz 8.4.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
@radarhere radarhere added the GIF label May 21, 2024
@radarhere
Copy link
Member

If I change your save command to have a disposal of 1

images[0].save(img_io, format="gif", save_all=True, append_images=images[1:], optimize=False, loop=0, disposal=1)

then the resulting image looks the same in Safari and Chrome. Is that sufficient to solve your problem?

animgif

The GIF specification describes disposal of 1 as "Do not dispose. The graphic is to be left in place", and our default disposal of 0 as "No disposal specified. The decoder is not required to take any action".

It may not be a bug as such, but just a different interpretation of the specification.

@radarhere radarhere changed the title Problem with pillow generated anim gifs in Safari Animated GIFs in Safari May 21, 2024
@kamenik
Copy link
Author

kamenik commented May 22, 2024

Ok, thank you for explanation ;).

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

No branches or pull requests

2 participants