如何在sorl缩略图3.2.5版本中的python代码中获取缩略图?

发布于 2024-10-22 00:28:29 字数 187 浏览 4 评论 0原文

sorl缩略图的文档仍然引用了get_thumbnail函数,但这在v.3.2.5中不存在。 (cannot import name get_thumbnail)

对于我的一生,我找不到任何关于此函数更改的参考,或者如何在此版本的 sorl 的 python 代码中生成缩略图。有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云不回头 2024-10-29 00:28:29

在我的特定情况下,我使用了定义了 extra_thumbnails 的 ThumbnailField:

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']})

image 字段将包含由 extra_thumbnails 定义的图像字典选项作为属性,令人惊讶地命名为 extra_thumbails

somemodel_instance.image.extra_thumbnails['inline_preview']

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']
维持三分热 2024-10-29 00:28:29

好吧,几周前我发现我之前实际上已经解决了这个问题,我什至写了一篇简短的博客文章 不记得了,- 拍了一下头。如果它只是您想要的 URL,您可以这样做:

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))

这有点 hackish,但它比 Chris 的解决方案更好,因为您可以调用任何缩略图大小,而不需要调整 extra_thumbnails场地。话虽这么说,我确实发现他的解决方案更干净,因为不需要从 sorl 进行内部导入,但两种方法都应该有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文