Skip to content

ValueError: image has no palette when show GIF #8921

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

Open
quaeast opened this issue Apr 21, 2025 · 5 comments · May be fixed by #8924
Open

ValueError: image has no palette when show GIF #8921

quaeast opened this issue Apr 21, 2025 · 5 comments · May be fixed by #8924
Labels

Comments

@quaeast
Copy link

quaeast commented Apr 21, 2025

What did you do?

from PIL import Image
import io


image_1 = '/Users/fangzidong/git_repo/mmwrastra/debug_data/debug_gif_img/no_palette.gif'


with open(image_1, 'rb') as f:
    image_bytes = f.read()
image = Image.open(io.BytesIO(image_bytes))
image.show()

What actually happened?

I got this error when i opening this image:

Image

Traceback (most recent call last):
  File "/Users/fangzidong/git_repo/mmwrastra/plg/image_io_debug.py", line 11, in <module>
    image.show()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/Image.py", line 2641, in show
    _show(self, title=title)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/Image.py", line 3811, in _show
    ImageShow.show(image, **options)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageShow.py", line 61, in show
    if viewer.show(image, title=title, **options):
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageShow.py", line 85, in show
    return self.show_image(image, **options)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageShow.py", line 112, in show_image
    return self.show_file(self.save_image(image), **options)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageShow.py", line 108, in save_image
    return image._dump(format=self.get_format(image), **self.options)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/Image.py", line 666, in _dump
    self.save(filename, format, **options)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/Image.py", line 2581, in save
    save_handler(self, fp, filename)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 1301, in _save_all
    _save(im, fp, filename, save_all=True)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 1321, in _save
    for im_frame in ImageSequence.Iterator(im_seq):
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageSequence.py", line 56, in __next__
    self.im.seek(self.position)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 165, in seek
    self._seek(f)
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 186, in _seek
    self.load()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageFile.py", line 400, in load
    self.load_end()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 480, in load_end
    self.im.putpalettealpha(self._frame_transparency, 0)
ValueError: image has no palette

What are your OS, Python and Pillow versions?

  • OS: macOS 15.0.1 24A348 arm
  • Python: Python 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:35:25) [Clang 16.0.6 ]
  • Pillow: 11.2.1
--------------------------------------------------------------------
Pillow 11.2.1
Python 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:35:25) [Clang 16.0.6 ]
--------------------------------------------------------------------
Python executable is /Users/fangzidong/miniconda3/envs/torch/bin/python3
System Python files loaded from /Users/fangzidong/miniconda3/envs/torch
--------------------------------------------------------------------
Python Pillow modules loaded from /Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL
Binary Pillow modules loaded from /Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.2.1
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.5.0
*** AVIF support not installed
--- 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.4
--- LIBTIFF support ok, loaded 4.7.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.10, harfbuzz 11.0.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
@luoxixiang23921
Copy link

Hi, I would like to work on this issue!

@aclark4life
Copy link
Member

aclark4life commented Apr 22, 2025

@quaeast Why not just call Image.open ?

Python 3.12.9 (main, Mar 23 2025, 16:34:48) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> img = Image.open("435668030-8d16446a-4b29-4a0f-9249-52edfa1532c1.gif")
>>> img.palette
<PIL.ImagePalette.ImagePalette object at 0x10546f740>

@quaeast
Copy link
Author

quaeast commented Apr 22, 2025

@aclark4life I tried to open it in this way, and it will return the same error. The key of this error is this image has a palette, but pillow tells me it does not have.

And I also tried to convert this image to ndarray frame by frame, but when it turns to the 9th frame, it will return ValueError: image has no palette. I checked the bytes of this gif, and i confirm this gif's every frame has a palette. I think may be it is because that some frames of this image is gray scale image and pillow convert it to L mode. This error may similar to this issue #6084

from PIL import Image

image = Image.open('435668030-8d16446a-4b29-4a0f-9249-52edfa1532c1.gif')

frames = []
try:
    while True:
        print(len(frames))
        frame = image.copy()
        frames.append(frame)
        image.seek(image.tell() + 1)
except EOFError:
    pass
0
1
2
3
4
5
6
7
Traceback (most recent call last):
  File "/Users/fangzidong/git_repo/mmwrastra/plg/image_io_debug.py", line 13, in <module>
    frame = image.copy()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/Image.py", line 1271, in copy
    self.load()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/ImageFile.py", line 400, in load
    self.load_end()
  File "/Users/fangzidong/miniconda3/envs/torch/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 480, in load_end
    self.im.putpalettealpha(self._frame_transparency, 0)
ValueError: image has no palette

@quaeast quaeast changed the title "ValueError: image has no palette" when opening GIF ValueError: image has no palette when opening GIF Apr 22, 2025
@quaeast quaeast changed the title ValueError: image has no palette when opening GIF ValueError: image has no palette when show GIF Apr 22, 2025
@aclark4life
Copy link
Member

aclark4life commented Apr 22, 2025

I can reproduce, but not sure if this is a Pillow bug.

Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> 
>>> image = Image.open('435668030-8d16446a-4b29-4a0f-9249-52edfa1532c1.gif')
>>> 
>>> frames = []
>>> try:
...     while True:
...         print(len(frames))
...         frame = image.copy()
...         frames.append(frame)
...         image.seek(image.tell() + 1)
... except EOFError:
...     pass
... 
0
1
2
3
4
5
6
7
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/Users/alex.clark/Developer/django-mongodb-cli/.venv/lib/python3.12/site-packages/pillow-11.2.0-py3.12-macosx-15.3-arm64.egg/PIL/Image.py", line 1271, in copy
    self.load()
  File "/Users/alex.clark/Developer/django-mongodb-cli/.venv/lib/python3.12/site-packages/pillow-11.2.0-py3.12-macosx-15.3-arm64.egg/PIL/ImageFile.py", line 396, in load
    self.load_end()
  File "/Users/alex.clark/Developer/django-mongodb-cli/.venv/lib/python3.12/site-packages/pillow-11.2.0-py3.12-macosx-15.3-arm64.egg/PIL/GifImagePlugin.py", line 480, in load_end
    self.im.putpalettealpha(self._frame_transparency, 0)
ValueError: image has no palette

@radarhere radarhere added the GIF label Apr 22, 2025
@radarhere radarhere linked a pull request Apr 23, 2025 that will close this issue
@radarhere
Copy link
Member

I've created #8924 to resolve this.

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.

4 participants