A django application to resize images using the thumbor service
Project description
A django application to resize images using the thumbor service.
Usage
Both thumbor_url templatetag and the generate_url helper uses the same arguments as libthumbor, you can check the wiki for more info.
On templates:
{% load thumbor_tags %}
<img src="{% thumbor_url '/media/image.jpg' width=300 %}" width="300" />
or
{% load thumbor_tags %}
<img src="{% thumbor_url model.image_field width=300 %}" width="300" />
If you need the result in a template variable, use assign_thumbor_url instead.
{% load thumbor_tags %} {% assign_thumbor_url ‘/media/image.jpg’ width=300 as thumb_url %} <img src=”{{ thumb_url }}” width=”300” />
Filters
Split filters with : (or use a list object):
{% load thumbor_tags %}
<img src="{% thumbor_url url filters='watermark(http://domain.com/watermark.png,-10,-10,20):brightness(10)' %}" />
<img src="{% thumbor_url url filters=filter_list %}" />
On code:
from django_thumbor import generate_url
resized = generate_url("/media/image.jpg", width=300)
Re-using argument sets (aliases)
You can re-use argument sets through globally defined aliases. This prevents repeating thumbnail parameters all over the code and can improve thumbor performance because thumbnails are re-used as well. If you’re migrating from django-easy-thumbnails, you’ll find the pattern very familiar, and it should make porting much more straight-forward.
On templates:
{% load thumbor_tags %}
<img src="{% thumbor_url '/media/image.jpg' alias="thumb-square" %}" />
On code:
from django_thumbor import generate_url
resized = generate_url("/media/image.jpg", alias="thumb-square")
And in your settings.py:
THUMBOR_ALIASES = {
'thumb-square': {
'width': 300,
'height': 300,
'filters': ['brightness(10)']}
}
Override server address
There is an extra parameter to specify a custom server to be used instead of settings.THUMBOR_SERVER.
On templates:
{% load thumbor_tags %}
<img src="{% thumbor_url '/media/image.jpg' thumbor_server='http://localhost:8888/foo' width=300 %}" width="300" />
On code:
from django_thumbor import generate_url
custom_server = "http://localhost:8888/foo"
resized = generate_url(
"/media/image.jpg", thumbor_server=custom_server, width=300)
Installation
pip install django-thumbor
Configuration
Add the app to the INSTALLED_APPS:
INSTALLED_APPS = (
# ...
'django_thumbor',
)
Here are the default settings that you can override:
# The host serving the thumbor resized images
THUMBOR_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 images
THUMBOR_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 statics
THUMBOR_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 images
THUMBOR_STATIC_URL = 'http://localhost:8000/static'
# The same security key used in the thumbor service to
# match the URL construction
THUMBOR_SECURITY_KEY = 'MY_SECURE_KEY'
# Default arguments passed to the `generate_url` helper or
# the `thumbor_url` templatetag
THUMBOR_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 = {}
Contributing
Install
Fork, clone, create a virtualenv and run:
git clone git://github.com/ricobl/django-thumbor.git
mkvirtualenv django-thumbor
make install
Test
Add tests on testproject/tests, add code and run:
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hmtvltk2-django-thumbor-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172f26c407c9f368d71182b1f03ac6766a04ed47975b030ce32cae9ffe4f2198 |
|
MD5 | 90c5a688431642a0ce633872e38be8ef |
|
BLAKE2b-256 | 161fe50a4c155a37b00d56e3f1be425172e3400bf398b097b4d641537c3fd10f |
Hashes for hmtvltk2_django_thumbor-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c30be89a89a31b2b7a876a3e20fea97b33ede92bdcc51338cf58a24623cbbfe |
|
MD5 | c1b4d0c302cfd813b103c0cd9ed3eb8e |
|
BLAKE2b-256 | 10b5de056673378d84c1498663b7ee3817a4e7de966fd722616e239f225cc671 |