Reputation: 48445
The documentation of sorl thumbnail still refers to the get_thumbnail
function, but this doesn't exist in v.3.2.5. (cannot import name get_thumbnail
)
For the life of me, I can't find any reference to what this function was changed to, or how to generate a thumbnail in the python code of this version of sorl. Any advice?
Upvotes: 3
Views: 1283
Reputation: 48445
Well, a few weeks ago I discovered I actually solved this problem before and I even wrote a short blog post about it without remembering, - smacks head. If it's only the URL you're after, you can do this:
from solr.thumbnail.main import DjangoThumbnail
img = imageObject # a normal image url returned from an ImageField
size = (100,100) # any tuple
img_resize_url = unicode(DjangoThumbnail(img, size))
It's a bit hackish, but it's better than Chris's solution in the sense that you can call any thumbnail size, without needing to adapt the extra_thumbnails
field. That being said, I do find his solution cleaner in the sense that there are no internal imports from sorl required, but both ways should work.
Upvotes: 1
Reputation: 48962
In my particular case, I've used an ThumbnailField with extra_thumbnails
defined:
class SomeModel(models.Model):
# other kwargs omitted for clarity
image = ThumbnailField(extra_thumbnails={
'inline_preview': {'size': (600,400)},
'small_thumb': {'size': (75,75), 'options':['crop', 'sharpen']})
The image
field will have a dict of the images defined by the extra_thumbnails
option as an attribute named, surprisingly, extra_thumbails
:
somemodel_instance.image.extra_thumbnails['inline_preview']
Upvotes: 2