diff --git a/easy_thumbnails/processors.py b/easy_thumbnails/processors.py index 7f7ba20c..7ca028c4 100644 --- a/easy_thumbnails/processors.py +++ b/easy_thumbnails/processors.py @@ -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) diff --git a/easy_thumbnails/tests/files/animated_mode_p.gif b/easy_thumbnails/tests/files/animated_mode_p.gif new file mode 100644 index 00000000..b09eed01 Binary files /dev/null and b/easy_thumbnails/tests/files/animated_mode_p.gif differ diff --git a/easy_thumbnails/tests/test_animated_formats.py b/easy_thumbnails/tests/test_animated_formats.py index f3cf81b9..6e20f563 100644 --- a/easy_thumbnails/tests/test_animated_formats.py +++ b/easy_thumbnails/tests/test_animated_formats.py @@ -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 = [] @@ -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}) \ No newline at end of file