使用thumbor服务调整图像大小的django应用程序

django-thumbor的Python项目详细描述


CI status on Travis CILatest django-thumbor PyPI versionNumber of downloads for django-thumbor on PyPICode coverage on CoverallsDependency Status on Gemnasium

django应用程序使用 thumbor服务。

用法

thumbor_urltemplateTag和generate_urlhelper都使用相同的 参数为libthumbor,您可以 查看wiki了解更多信息。

在模板上:

{% load thumbor_tags %}
<imgsrc="{% thumbor_url '/media/image.jpg' width=300 %}"width="300"/>

or

{% load thumbor_tags %}
<imgsrc="{% thumbor_url model.image_field width=300 %}"width="300"/>

如果需要模板变量中的结果,请改用assign_thumbor_url。

{% load thumbor_tags %} {% assign_thumbor_url ‘/media/image.jpg’ width=300 as thumb_url %} <img src=”{{ thumb_url }}” width=”300” />

过滤器

使用拆分filters:(或使用list对象):

{% load thumbor_tags %}
<imgsrc="{% thumbor_url url filters='watermark(http://domain.com/watermark.png,-10,-10,20):brightness(10)' %}"/><imgsrc="{% thumbor_url url filters=filter_list %}"/>

打开代码:

fromdjango_thumborimportgenerate_urlresized=generate_url("/media/image.jpg",width=300)

重新使用参数集(别名)

可以通过全局定义的别名重用参数集。这防止 在代码中重复缩略图参数,可以改进thumbor 性能,因为缩略图也被重复使用。如果你要迁移 从django简单的缩略图中,您会发现模式非常熟悉,而且 会使移植更加直接。

在模板上:

{% load thumbor_tags %}
<imgsrc="{% thumbor_url '/media/image.jpg' alias="thumb-square"%}"/>

打开代码:

fromdjango_thumborimportgenerate_urlresized=generate_url("/media/image.jpg",alias="thumb-square")

在你的settings.py

THUMBOR_ALIASES={'thumb-square':{'width':300,'height':300,'filters':['brightness(10)']}}

覆盖服务器地址

有一个额外的参数指定要使用的自定义服务器,而不是 settings.THUMBOR_SERVER

在模板上:

{% load thumbor_tags %}
<imgsrc="{% thumbor_url '/media/image.jpg' thumbor_server='http://localhost:8888/foo' width=300 %}"width="300"/>

打开代码:

fromdjango_thumborimportgenerate_urlcustom_server="http://localhost:8888/foo"resized=generate_url("/media/image.jpg",thumbor_server=custom_server,width=300)

安装

pip install django-thumbor

配置

将应用程序添加到INSTALLED_APPS

INSTALLED_APPS=(# ...'django_thumbor',)

以下是您可以覆盖的默认设置:

# The host serving the thumbor resized imagesTHUMBOR_SERVER='http://localhost:8888'# The prefix for the host serving the original images# This must be a resolvable address to allow thumbor to reach the imagesTHUMBOR_MEDIA_URL='http://localhost:8000/media'# If you want the static to be handled by django thumbor# default as False, set True to handle it if you host your staticsTHUMBOR_STATIC_ENABLED=False# The prefix for the host serving the original static images# this must be a resolvable address to allow thumbor to reach the imagesTHUMBOR_STATIC_URL='http://localhost:8000/static'# The same security key used in the thumbor service to# match the URL constructionTHUMBOR_SECURITY_KEY='MY_SECURE_KEY'# Default arguments passed to the `generate_url` helper or# the `thumbor_url` templatetagTHUMBOR_ARGUMENTS={}# An alias represents a named set of arguments to the generate_url function# or thumbor_url template tag. Use it to share general thumbnail# configurations without repeating yourself.THUMBOR_ALIASES={}

贡献

安装

fork,克隆,创建一个virtualenv并运行:

git clone git://github.com/ricobl/django-thumbor.git
mkvirtualenv django-thumbor
make install

测试

testproject/tests上添加测试,添加代码并运行:

make test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android首选项相同getPreference()值的不同数据   字符串如何在Java中连接两个列表中的单词   安卓 Java Socket编程:检测客户端和服务器是否连接   使用JTextField的java无法将值转换为int   在java中,如何在不通过超级构造函数设置的情况下将消息设置为自定义异常类   用于标识属性值的java正则表达式模式   Android中的java不可见谷歌地图   java正确取消启动ExecutorService的JavaFX任务   在非活动java类中使用安卓的融合位置提供程序,并在主活动类中获取经度和纬度   spring为什么我的大摇大摆不能用springboot在java中工作?   java JSF(2.2)ViewScope在Weblogic 12.2.1.2和JDK 8上使用Spring 4.3.7(在Mac OS和Docker Oracle Linux环境上)   java如何用一个按钮提高计时器速度   java如何检查字符是否是元音?   注册表引用了不存在的Java运行时环境安装或运行时已损坏错误   来自ResultSet java的mysql getDateTime   maven LanguageTool Java API是否具有“无用”依赖关系?   twitter api身份验证的java Trycatch问题   java在Apache Struts 1.1中是否可以显式白名单?   安卓致命异常:主java。lang.RuntimeException:被问及未知片段