Thumbnail generation of GIF fails with `cannot write mode P as JPEG` since 2.10
Hello,
When updating easy_thumbnails[svg] from 2.9.0 to 2.10.0, I noticed the following regression.
- Take this GIF image (not sure if the bug appears with all GIF files)
- 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.
👍 We've faced the same issue after updating from 2.8.5 to 2.10.0.
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.
@pecheneff @philippemilink you may pip install -e from my PR here: #657 to check if it solves to problem on your side.
Yes, I tested and your PR solves my problem, thanks!
Ok, thanks for your feedback. Let's hope for a quick release.