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

Workaround to prevent thumbnail creation for GIFs #505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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