easy-thumbnails icon indicating copy to clipboard operation
easy-thumbnails copied to clipboard

Thumbnail generation of GIF fails with `cannot write mode P as JPEG` since 2.10

Open philippemilink opened this issue 1 year ago • 5 comments

Hello,

When updating easy_thumbnails[svg] from 2.9.0 to 2.10.0, I noticed the following regression.

  1. Take this GIF image (not sure if the bug appears with all GIF files)
  2. Execute the following code:
    from easy_thumbnails.files import get_thumbnailer
    
    t = get_thumbnailer("Steam_locomotive_work2.gif")
    thumb = t.get_thumbnail({'size': (50, 50), 'crop': True})
    

The following exception is raised:

Traceback (most recent call last):
  File "lib/python3.12/site-packages/PIL/JpegImagePlugin.py", line 639, in _save
    rawmode = RAWMODE[im.mode]
              ~~~~~~~^^^^^^^^^
KeyError: 'P'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "lib/python3.12/site-packages/easy_thumbnails/files.py", line 513, in get_thumbnail
    thumbnail = self.generate_thumbnail(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/easy_thumbnails/files.py", line 401, in generate_thumbnail
    img = engine.save_pil_image(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/easy_thumbnails/engine.py", line 77, in save_pil_image
    image.save(destination, format=format, **options)
  File "lib/python3.12/site-packages/PIL/Image.py", line 2568, in save
    save_handler(self, fp, filename)
  File "lib/python3.12/site-packages/PIL/JpegImagePlugin.py", line 642, in _save
    raise OSError(msg) from e
OSError: cannot write mode P as JPEG

It works as expected with version 2.9.0.

I guess it's related to https://github.com/SmileyChris/easy-thumbnails/pull/628, but even if this PR is mentioned as experimental, it introduces a regression.

philippemilink avatar Nov 20 '24 21:11 philippemilink

👍 We've faced the same issue after updating from 2.8.5 to 2.10.0.

pecheneff avatar Dec 07 '24 12:12 pecheneff

2.10 got experimental support for animated formats. But I guess it was merged too early, sorry for the troubles! I'll have a look.

benzkji avatar Jan 07 '25 13:01 benzkji

@pecheneff @philippemilink you may pip install -e from my PR here: #657 to check if it solves to problem on your side.

benzkji avatar Jan 13 '25 09:01 benzkji

Yes, I tested and your PR solves my problem, thanks!

philippemilink avatar Jan 16 '25 21:01 philippemilink

Ok, thanks for your feedback. Let's hope for a quick release.

benzkji avatar Jan 17 '25 09:01 benzkji