Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion easy_thumbnails/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def apply_to_frames(self, method, *args, **kwargs):
new_frames[0].save(
write_to, format=self.im.format, save_all=True, append_images=new_frames[1:]
)
return Image.open(write_to)
to_return = Image.open(write_to)
# mode changes are not always correctly applied, probably due to the BytesIO and save workaround
# so force them here.
if to_return.mode != new_frames[0].mode:
to_return = to_return.convert(new_frames[0].mode)
return to_return

def __getattr__(self, key):
method = getattr(self.im, key)
Expand Down
Binary file added easy_thumbnails/tests/files/animated_mode_p.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions easy_thumbnails/tests/test_animated_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from easy_thumbnails import processors
from unittest import TestCase

from easy_thumbnails.files import get_thumbnailer


def create_animated_image(mode='RGB', format="gif", size=(1000, 1000), no_frames=6):
frames = []
Expand Down Expand Up @@ -81,3 +83,10 @@ def test_background(self):
# indeed processed?
self.assertEqual(frames_count, processed_frames_count)
self.assertEqual(processed.size, (1000, 1800))

def test_gif_with_mode_p(self):
with open("easy_thumbnails/tests/files/animated_mode_p.gif", "rb") as im:
t = get_thumbnailer(im, "easy_thumbnails/tests/files/animated_mode_p.gif")
# should not fail because of wrong mode
# https://github.com/SmileyChris/easy-thumbnails/issues/653
t.get_thumbnail({'size': (500, 50), 'crop': True})
Loading