Skip to content

GIF encoder: black pixels incorrectly cropped when disposal=2 #8746

@lucach

Description

@lucach

What did you do?

I created a GIF with these two identically sized (120x120) frames:

first = Image.open("first.png")
second = Image.open("second.png")
first.save("out.gif", save_all=True, append_images=[second], disposal=2, loop=0, duration=500)

Image Image

What did you expect to happen?

Pillow creates a GIF with two frames, each 120x120.

What actually happened?

Pillow creates a GIF with a cropped second frame:

> identify out.gif
out.gif[0] GIF 120x120 120x120+0+0 8-bit sRGB 8c 0.000u 0:00.000
out.gif[1] GIF 90x90 120x120+15+15 8-bit sRGB 8c 1147B 0.000u 0:00.000

On most viewers (Safari being an exception, as far as I can tell), the GIF is displayed incorrectly:

Image

This seems related to the already-fixed #8222, but disabling the optimizer does not solve the problem in this case.
On the other hand, changing the disposal method, or having a non-black color like RGB(1,1,1), is enough to avoid this bug.

What are your OS, Python and Pillow versions?

--------------------------------------------------------------------
Pillow 11.1.0
Python 3.13.1 (main, Dec  3 2024, 17:59:52) [Clang 16.0.0 (clang-1600.0.26.4)]
--------------------------------------------------------------------
Python executable is /Users/lucach/tmp/bin/python3
Environment Python files loaded from /Users/lucach/tmp
System Python files loaded from /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.13
--------------------------------------------------------------------
Python Pillow modules loaded from /Users/lucach/tmp/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from /Users/lucach/tmp/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.1.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.5.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.2.2
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.16, harfbuzz 10.1.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------

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