更改缩略图格式

发布于 2024-12-11 13:00:34 字数 976 浏览 6 评论 0原文

有人可以给我一个如何更改 django 模板标签中的 SORL 缩略图格式的示例吗?

我在这里阅读了文档: http://thumbnail.sorl.net/template.html#thumbnail

并尝试过各种方法都没有效果。我收到类似于以下内容的错误: “thumbnail”标签收到了一个错误的参数:“format”

我的代码在没有“format =“png””部分的情况下工作正常,它只是制作一个 jpg 缩略图。不过,我想要一个 png 缩略图。 {%缩略图product.main_image.picture 84x84 format =“png”作为图像%}

另外,添加THUMBNAIL_FORMAT =“PNG” 对我的 settings.py 没有执行任何操作

谢谢,



更新: 我是这样解决问题的:

所以 Issac 和 zachwood 是对的。这是一个依赖于版本的事情。我这样解决了我的问题:

1.) 升级到最新的sorl
1.1) 同步数据库
2.) 在设置中,更改 THUMBNAIL_DEBUG = True
3.) 添加结束标签,使模板看起来像:

        {% thumbnail product.main_image.picture "400x284" format="PNG"  as image %}

<img src="{{ media_url }}{{ image }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ product.short_description }}"/>

        {% endthumbnail %}

它有效!

4.)

can someone please give me an example of how to change the SORL-thumbnail format in the django template tag.

I've read the documentation here: http://thumbnail.sorl.net/template.html#thumbnail

and have tried various ways of implimenting to no avail. I get errors similar to:
'thumbnail' tag received a bad argument: 'format'

My code works fine without the " format="png" " part, it just makes a jpg thumbnail. However, I want a png thumbnail.
{% thumbnail product.main_image.picture 84x84 format="png" as image %}

Also, adding THUMBNAIL_FORMAT = "PNG"
to my settings.py did nothing

Thanks,



UPDATE:
HERE's HOW I FIXED THE PROBLEM:

So Issac and zachwood were right on. This was a version dependent thing. I resolved my problem this way:

1.) upgrade to newest sorl
1.1) syncdb
2.) in settings, changed THUMBNAIL_DEBUG = True
3.) added closing tag so the templates looked like :

        {% thumbnail product.main_image.picture "400x284" format="PNG"  as image %}

<img src="{{ media_url }}{{ image }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ product.short_description }}"/>

        {% endthumbnail %}

It worked!

4.)

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

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

发布评论

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

评论(1

不离久伴 2024-12-18 13:00:34

不幸的是,Satchmo 使用 SORL-Thumbnail 版本 3.2.5,这些文档适用于 11。我的猜测是他们不支持版本 3.x 中的格式。我没有找到相关文档,但您可以通过深入研究代码来确定。

如果我没记错的话,您可以将库换成版本 11,但是您必须遍历所有使用模板标记的模板,并在每次使用后添加 {% endthumbnail %} 标记(结束标记不是在 3.x 版本中使用)。

Unfortunately Satchmo uses SORL-Thumbnail version 3.2.5, those docs are for 11. My guess is they didn't support formats in version 3.x. I haven't had any luck finding docs for it but you can probably dig through the code to be sure.

If I remember correctly you can swap out the library for version 11, but you'll have to go through all the templates that use the template tag and add the {% endthumbnail %} tag after each time it's used (the endtag wasn't used back in version 3.x).

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