Skip to content

Commit

Permalink
Workaround to prevent thumbnail creation for GIFs
Browse files Browse the repository at this point in the history
  • Loading branch information
wfehr committed Oct 23, 2018
1 parent d3eb3d7 commit f22f0b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions easy_thumbnails/conf.py
Expand Up @@ -186,6 +186,11 @@ class Settings(AppSettings):
Instead of a tuple, you can also set this to ``True`` in order to always
preserve the original extension.
"""
THUMBNAIL_PREVENT_GIF_CONVERT = False
"""
Prevent thumbnail creation for GIFs. Created thumbnails for GIFs have no
preserved animations, set to ``True`` if you want to keep them.
"""
THUMBNAIL_TRANSPARENCY_EXTENSION = 'png'
"""
The type of image to save thumbnails with a transparency layer (e.g. GIFs
Expand Down
9 changes: 8 additions & 1 deletion easy_thumbnails/templatetags/thumbnail.py
@@ -1,3 +1,4 @@
import os
import re
from base64 import b64encode
import mimetypes
Expand Down Expand Up @@ -113,7 +114,13 @@ def render(self, context):
return self.bail_out(context)

try:
thumbnail = get_thumbnailer(source).get_thumbnail(opts)
bits = False
if settings.THUMBNAIL_PREVENT_GIF_CONVERT:
bits = os.path.splitext(getattr(source, 'url', source.name))
if bits and bits[1] == '.gif':
thumbnail = source
else:
thumbnail = get_thumbnailer(source).get_thumbnail(opts)
except Exception:
if raise_errors:
raise
Expand Down

0 comments on commit f22f0b9

Please sign in to comment.