Skip to content

Commit 9133c99

Browse files
committed
Try to use easy_thumbnails for ImageWidget thumbnails before falling back to full-size images.
1 parent fb6b640 commit 9133c99

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

form_utils/widgets.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ def thumbnail(image_path, width, height):
2222
t = DjangoThumbnail(relative_source=image_path, requested_size=(width,height))
2323
return u'<img src="%s" alt="%s" />' % (t.absolute_url, image_path)
2424
except ImportError:
25-
def thumbnail(image_path, width, height):
26-
absolute_url = posixpath.join(settings.MEDIA_URL, image_path)
27-
return u'<img src="%s" alt="%s" />' % (absolute_url, image_path)
25+
try:
26+
from easy_thumbnails.files import get_thumbnailer
27+
def thumbnail(image_path, width, height):
28+
thumbnail_options = dict(size=(width, height), crop=True)
29+
thumbnail = get_thumbnailer(image_path).get_thumbnail(thumbnail_options)
30+
return u'<img src="%s" alt="%s" />' % (thumbnail.url, image_path)
31+
except ImportError:
32+
def thumbnail(image_path, width, height):
33+
absolute_url = posixpath.join(settings.MEDIA_URL, image_path)
34+
return u'<img src="%s" alt="%s" />' % (absolute_url, image_path)
2835

2936
class ImageWidget(forms.FileInput):
3037
template = '%(input)s<br />%(image)s'

0 commit comments

Comments
 (0)