From 7365f165ad601a8cd8905d8617d6f4c23b9fd601 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 4 Jun 2024 21:53:20 +0200 Subject: [PATCH] Thumbnails: Keep frame durations of GIFs (#4183) --- src/pretix/helpers/thumb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pretix/helpers/thumb.py b/src/pretix/helpers/thumb.py index 7ff9af946..5ebf9d70b 100644 --- a/src/pretix/helpers/thumb.py +++ b/src/pretix/helpers/thumb.py @@ -180,7 +180,11 @@ def create_thumbnail(source, size, formats=None): except: raise ThumbnailError('Could not load image') - frames = [resize_image(frame, size) for frame in ImageSequence.Iterator(image)] + frames = [] + durations = [] + for f in ImageSequence.Iterator(image): + durations.append(f.info.get("duration", 1000)) + frames.append(resize_image(f, size)) image_out = frames[0] save_kwargs = {} source_ext = os.path.splitext(source_name)[1].lower() @@ -198,6 +202,8 @@ def create_thumbnail(source, size, formats=None): 'loop': image.info.get('loop', 0), 'save_all': True, } + if len(frames) > 1 and 'duration' in image.info: + save_kwargs['duration'] = durations else: target_ext = 'png' quality = None