Skip to content
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

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

Open
philippemilink opened this issue Nov 20, 2024 · 5 comments

Comments

@philippemilink
Copy link

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 #628, but even if this PR is mentioned as experimental, it introduces a regression.

@pecheneff
Copy link

pecheneff commented Dec 7, 2024

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

@benzkji
Copy link
Contributor

benzkji commented Jan 7, 2025

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
Copy link
Contributor

benzkji commented Jan 13, 2025

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

@philippemilink
Copy link
Author

philippemilink commented Jan 16, 2025

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

@benzkji
Copy link
Contributor

benzkji commented Jan 17, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants