Search code examples
pythonthumbnailsgifpython-imaging-libraryraspistill

IOError: codec configuration error when reading image file


I am trying to get a thumbnail of a gif image using Pillow 4.3.0, Python 2.7.13, Debian 9.1

from PIL import Image

im = Image.open("Pictures/image.gif")
im.thumbnail((240,160))
im.save("Thumbnails/thumbnail.gif")

But I cannot do it. This is the log:

Traceback (most recent call last):
  File "testpy.py", line 4, in <module>
    im.thumbnail((240,180))
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1843, in 
  thumbnail
    im = self.resize(size, resample)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1541, in 
  resize
    self.load()
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 244, in 
  load
    raise_ioerror(err_code)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 59, in 
  raise_ioerror
    raise IOError(message + " when reading image file")
IOError: codec configuration error when reading image file

This issue doesn't occur with other formats (jpg, png, bmp).

Any help is very appreciated.

Edit: This happens specifically on pictures made with raspistill camera with gif encoding mode selected. If don't select encoding mode at all, it works well. But if not selecting encoding, then all the images are treated as jpg, which is not what I want.


Solution

  • The raspistill camera gif images contain a bit depth of 11,

    >>> im.tile
    [('gif', (0, 0, 100, 100), 792, (11, False))]
    

    while Pillow supports gif images only up to a bit depth of 8.

    I posted this question on Pillow github page and they are supposed to fix it soon. https://github.com/python-pillow/Pillow/issues/2811