Skip to content

Pillow 11.0.0 throws ValueError when saving GIF #8493

@ArcasCZ

Description

@ArcasCZ

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?

  • OS: Windows 11 / Ubuntu 24.04.1 LTS
  • Python: 3.12
  • Pillow: 11.0.0
--------------------------------------------------------------------
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 #8366

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