Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

filebrowser thumbnail #209

Closed
anothergituser opened this Issue · 1 comment

2 participants

@anothergituser

Hi,
When using FileBrowseField from filebrowser extension to choose an image i had the problem that easy_thumbnails doesn't work with plain FileObject that FileBrowseField returns (maybe because FileObject can be anything not just images)
Anyway what i propose is that if the object is not a ThumbnailerImageFieldFile or an ImageFieldFile that FileObject be checked if it's an actual image and not some other file.
If so create the thumb.
What i ended up doing is to create my own tag and process the image using easy_thumbs like so (inside your app tags file)

from django.db.models.fields.files import ImageFieldFile, FileField
from easy_thumbnails.files import get_thumbnailer
# simple tag to output thumbnails
# using easy_thumbnails from a FileObject
# note that easy_thumbnails only supppor ImageFileField
# and not FileObject because FileObject can be anything
# and that the image we pass needs to be made an instance of
# ImageFieldFile
# from here
# http://stackoverflow.com/questions/1569698/create-return-a-default-imagefieldfile-from-inside-a-function
@register.simple_tag
def file_thumbnail_url(obj, size):
    img = ImageFieldFile(instance=None, field=FileField(), name=obj.path)
    w,h = size.split("x")
    url = get_thumbnailer(img).get_thumbnail({'size':(w,h),'crop':True}).url
    return url

And inside your template

<img src="{% file_thumbnail_url myobject.image '160x120' %}" />

after loading your tag.

This surely can be refined but i hope it can be incorporated inside the thumbnail tag or thumnail_url filter that easy_thumbnails provides

@SmileyChris
Owner

Easy-thumbnails expects the source to be a Django File-like object. If a FileObject meets this criteria, then you could just use the thumbnailer filter like this:
{% thumbnail myobject.image|thumbnailer:myobject.image.name ... %}

If it doesn't meet this criteria, then I think a custom tag is in order. And this seems like something that would better live in the filebrowser extension codebase (or just third party code) than in easy-thumbnails core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.