使用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 ListView显示的数字不超过8位   java什么导致警告“Classpath entry/XXX/XXX.jar将不会导出或发布。可能会导致运行时ClassNotFoundException。”   java使用Spring容器在非Spring对象上调用方法,允许参数连接?   java Android:当另一个手指已经在触摸屏幕时,是否可以处理一次点击?   java Veil加载JFrame上的图像或加载面板   JavaSpring没有为Redis缓存上的记录设置过期时间   java异常:SparkException:任务不可序列化   java Android studio用户注册数据未插入firebase数据库   java在StackPane中的区域图上覆盖节点   java获取活动UI的“会话已过期”消息   java组织。冬眠MappingNotFoundException:资源:*hbm。找不到xml   java Mockito mock在尝试存根包保护的方法时调用实方法实现