Skip to content

Instantly share code, notes, and snippets.

@sbaechler
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbaechler/e1196d0e659d43e31209 to your computer and use it in GitHub Desktop.
Save sbaechler/e1196d0e659d43e31209 to your computer and use it in GitHub Desktop.
A replacement thumbnailer function for FeinCMS that uses sorl
# coding: utf-8
"""
Thumbnailer class for FeinCMS. Allows using sorl thumbnail as default thumbnailer.
Use this if you have mediafiles stored on S3.
Add this line to your settings:
FEINCMS_MEDIALIBRARY_THUMBNAIL = 'feincms_sorl_thumbnailer.thumbnailer'
"""
from __future__ import unicode_literals
from sorl.thumbnail import get_thumbnail
def thumbnailer(mediafile, dimensions='100x100', quality=65, **kwargs):
"""
Function called by FeinCMS medialibrary.thumbnail.admin_thumbnail
:param mediafile: - the mediafile object
:param kwargs: - options passed to the thumbnailer
:return: - URL of the thumbnail
"""
if mediafile.type == 'image':
im = get_thumbnail(mediafile.file, dimensions, quality=quality)
return im.url
return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment