一个django应用程序,使用thumbor服务调整图像大小

hmtvltk2-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_url助手都使用相同的方法 参数为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_thumb or_url。在

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

过滤器

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

^{pr2}$

代码:

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

Re使用参数集(别名)

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

在模板上:

{% 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={}

贡献

安装

分叉,克隆,创建一个virtualenv然后运行:

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

测试

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

make test

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

推荐PyPI第三方库


热门话题
JFrame中的Java多线程   java Servlet异常映射   java无法从输出流读取   swing Java带来的小程序GUI问题   java什么原因导致错误“'void'类型此处不允许”以及如何修复它?   Java选择器select(长)与selectNow的区别   java自定义arraylist<mygames>获得不同   java Icepdf注释让页面消失   java反向整数数组   java I在生成同步“无法解析配置的所有依赖项”时遇到此错误:app:debugRuntimeClasspath   多个虚拟机上的java线程访问单个DB实例上的表,有时会导致性能低下和异常   swing更改Java中的默认按钮,使其看起来“更好”   java慢速MQ主题订阅。并行化不能提高性能   java运行Boggle Solver需要一个多小时。我的代码怎么了?   数据库中的java循环与应用程序中的java循环   正则表达式匹配${123…456}并在Java中提取2个数字?   java如何制作我们软件的试用版   Java内存参数计算   从另一个类调用方法时出现java问题