python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

Pillow 11.0.0 throws ValueError when saving GIF #8493

Open ArcasCZ opened 4 weeks ago

ArcasCZ commented 4 weeks ago

What did you do?

I'm saving a GIF created from series of PNG.

What did you expect to happen?

The GIF is created.

What actually happened?

Traceback (most recent call last):
  File "/root/.local/lib/python3.12/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/strawberry-py/modules/fun/fun/module.py", line 437, in lick
    with BytesIO() as image_binary:
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/PIL/Image.py", line 2605, in save
    save_handler(self, fp, filename)
  File "/usr/local/lib/python3.12/site-packages/PIL/GifImagePlugin.py", line 774, in _save_all
    _save(im, fp, filename, save_all=True)
  File "/usr/local/lib/python3.12/site-packages/PIL/GifImagePlugin.py", line 787, in _save
    if not save_all or not _write_multiple_frames(im, fp, palette):
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/PIL/GifImagePlugin.py", line 700, in _write_multiple_frames
    background_im.putpalette(im_frames[0].im.palette)
  File "/usr/local/lib/python3.12/site-packages/PIL/Image.py", line 2103, in putpalette
    self.load()  # install new palette
    ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/PIL/Image.py", line 909, in load
    self.im.putpalette(self.palette.mode, mode, arr)
ValueError: invalid palette size

This happens only on Pillow 11.0.0 with disposal=2.

What are your OS, Python and Pillow versions?

--------------------------------------------------------------------
Pillow 11.0.0
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is C:\Program Files\Python312\python.exe
System Python files loaded from C:\Program Files\Python312
--------------------------------------------------------------------
Python Pillow modules loaded from C:\Program Files\Python312\Lib\site-packages\PIL
Binary Pillow modules loaded from C:\Program Files\Python312\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.0.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- JPEG support ok, compiled for libjpeg-turbo 3.0.4
--- 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 not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

https://github.com/strawberry-py/strawberry-fun/blob/main/fun/module.py#L437

The error happens only on 11.0.0 verison, previous 10.4.0 works fine. I assume it might be related to https://github.com/python-pillow/Pillow/pull/8366

radarhere commented 4 weeks ago

Could we get a copy of the PNG images you are using as input?

ArcasCZ commented 4 weeks ago

Hi,

it happens with all images saved in the ./fun/data folder, e.g. https://github.com/strawberry-py/strawberry-fun/tree/main/fun/data/lick

radarhere commented 4 weeks ago

I've created #8494

ArcasCZ commented 6 days ago

Hi, is there any ETA for this fix?

hugovk commented 6 days ago

Assuming it's reviewed and merged it'll be in next release on 2nd January.

You can help by reviewing the PR and testing it to confirm if it fixes your problem.