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 encoder: black pixels incorrectly cropped when disposal=2 #8746

Open
lucach opened this issue Feb 11, 2025 · 2 comments · May be fixed by #8748
Open

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

lucach opened this issue Feb 11, 2025 · 2 comments · May be fixed by #8748
Labels

Comments

@lucach
Copy link

lucach commented Feb 11, 2025

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

I've created #8748 to resolve this.

With it, your code creates

Image

@lucach
Copy link
Author

lucach commented Feb 12, 2025

Looks great, thanks for the quick turnaround and the fix!

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