diff --git a/src/pretix/helpers/templatetags/thumb.py b/src/pretix/helpers/templatetags/thumb.py index ddc00d35df..49d77f3957 100644 --- a/src/pretix/helpers/templatetags/thumb.py +++ b/src/pretix/helpers/templatetags/thumb.py @@ -1,6 +1,7 @@ import logging from django import template +from django.core.files import File from django.core.files.storage import default_storage from pretix.helpers.thumb import get_thumbnail @@ -11,6 +12,8 @@ logger = logging.getLogger(__name__) @register.filter def thumb(source, arg): + if isinstance(source, File): + source = source.name try: return get_thumbnail(source, arg).thumb.url except: diff --git a/src/pretix/helpers/thumb.py b/src/pretix/helpers/thumb.py index bba03ff2dc..66c9553a1a 100644 --- a/src/pretix/helpers/thumb.py +++ b/src/pretix/helpers/thumb.py @@ -4,6 +4,7 @@ from io import BytesIO from django.core.files.base import ContentFile from django.core.files.storage import default_storage from PIL import Image +from PIL.Image import LANCZOS from pretix.helpers.models import Thumbnail @@ -41,9 +42,8 @@ def get_sizes(size, imgsize): return (int(imgsize[0] * hfactor), size[1]), None -def create_thumbnail(source, size): - if isinstance(source, str): - source = default_storage.open(source) +def create_thumbnail(sourcename, size): + source = default_storage.open(sourcename) image = Image.open(BytesIO(source.read())) try: image.load() @@ -51,7 +51,7 @@ def create_thumbnail(source, size): raise ThumbnailError('Could not load image') scale, crop = get_sizes(size, image.size) - image = image.resize(scale) + image = image.resize(scale, resample=LANCZOS) if crop: image = image.crop(crop) @@ -61,7 +61,7 @@ def create_thumbnail(source, size): image.save(fp=buffer, format='PNG') imgfile = ContentFile(buffer.getvalue()) - t = Thumbnail.objects.create(source=source, size=size) + t = Thumbnail.objects.create(source=sourcename, size=size) t.thumb.save(name, imgfile) return t diff --git a/src/pretix/presale/templates/pretixpresale/event/index.html b/src/pretix/presale/templates/pretixpresale/event/index.html index 04b734718f..218dd30748 100644 --- a/src/pretix/presale/templates/pretixpresale/event/index.html +++ b/src/pretix/presale/templates/pretixpresale/event/index.html @@ -225,7 +225,7 @@ data-title="{{ item.name|force_escape|force_escape }}" {# Yes, double-escape to prevent XSS in lightbox #} data-lightbox="{{ item.id }}"> - {{ item.name }} {% endif %} @@ -348,7 +348,7 @@ data-title="{{ item.name|force_escape|force_escape }}" {# Yes, double-escape to prevent XSS in lightbox #} data-lightbox="{{ item.id }}"> - {{ item.name }} {% endif %}