Last active
August 29, 2015 14:05
-
-
Save sbaechler/e1196d0e659d43e31209 to your computer and use it in GitHub Desktop.
A replacement thumbnailer function for FeinCMS that uses sorl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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