拇指图像服务的最小接口
django-thumborize的Python项目详细描述
thumbor映像服务的最小接口。
功能
简易拇指网址
通过调用简单的函数,轻松构建带有参数和过滤器的thumborurl。
默认过滤器
将默认筛选器设置为在缩略图URL上使用。 这些过滤器可以被任何使用不同参数指定相同过滤器的调用重写。
柔性过滤器规范< EH3>
筛选器可以是由:、alist或dict分隔的字符串。有关更多信息,请参见用法。
用法
fromthumborizeimportThumborURL# Filters as string.thumbor_url=ThumborURL("http://path/to/image.png",width=320,filters="quality(80):grayscale()")# Filters as list.thumbor_url=ThumborURL("http://path/to/image.png",width=320,filters=["quality(80)","grayscale()"])# Filters as dict.thumbor_url=ThumborURL("http://path/to/image.png",width=320,filters={"quality":"(80)","grayscale":"()",})thumbor_url.generate()'http://localhost:8888/JiuVg9d5Mry_kw4odvb5Zh1C_BY=/320x0/filters:quality(80):grayscale()/http://path/to/image.png'
链接
fromthumborizeimportThumborURLthumbor_url=ThumborURL("http://path/to/image.png")small_gray_image=thumbor_url.grayscale().resize(width=100,height=100)small_gray_image.generate()'http://localhost:8888/RFsfJakG9BsJUcbY2l1M6D5tthQ=/100x100/filters:grayscale()/http://path/to/image.png'low_quality_image=thumbor_url.quality(40).width(200)'http://localhost:8888/SB1ILIArmGzsd90-Mz-TxJVHwqI=/200x0/filters:quality(40)/http://path/to/image.png'# Original ThumborURL instance.thumbor_url.generate()'http://localhost:8888/O0Zqo6DMqqXHORdYncuspoaJlr0=/http://path/to/image.png'
快捷方式
importthumborizethumborize.url("http://path/to/image.png",width=320,height=300)'http://localhost:8888/DYStA-Xwisc37dVz7bdXZ3u63QI=/320x300/http://path/to/image.png'
模板
{% load thumborize %} <!-- Filters as string --><imgsrc="{% thumborize some_url width=320 filters='quality(80):grayscale()' %}"/><!-- Filters as a list object --><imgsrc="{% thumborize some_url width=320 filters=filter_list %}"/>
安装
使用pip安装
要使用django thumborize模板标记,必须将应用程序添加到INSTALLED_APPS: 配置基本拇指设置:$ pip install django-thumborize
INSTALLED_APPS=(# Other django apps.."thumborize",# Any order is fine.)
# Thumbor host URL.THUMBOR_SERVER="http://localhost:8888/"# This key must be the same used in thumbor# host to build safe URLs correctly.THUMBOR_SECURITY_KEY="MY_SECURE_KEY"# Default filters are optional.THUMBOR_DEFAULT_FILTERS={"quality":"(80)","grayscale":"()",}
测试
安装
首先克隆存储库,然后运行make install以安装开发人员需求。
运行测试
运行make test以运行测试。