Skip to main content

django-thumbor

CI status on Travis CI Latest django-thumbor PyPI version Number of downloads for django-thumbor on PyPI

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
cd django-thumbor
pipenv shell
make install

Test

Add tests on testproject/tests, add code and run:

make test

Test Server

  • Instal thumbor server: pip install thumbor

  • Run thumbor: thumbor

  • Run local server: make run

  • visit http://127.0.0.1:8000/:

Metadata

Release files for django-thumbor 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-thumbor 0.6.0
File Size Uploaded Provenance
django_thumbor-0.6.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-thumbor 0.6.0
File Interpreter ABI Platform
django_thumbor-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / django_thumbor-0.6.0.tar.gz

Download URL django_thumbor-0.6.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cce79a83b66abfdd5c99a60bc9ff47d2eea5f10acf11a8b810aa7ebc07ed74a5
BLAKE2b-256 checksum
How to use checksums
ba4938cfe18f46844ce92371c90acb1db65d6d0645d9baf41731f7308e4924b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Release files / django_thumbor-0.6.0-py3-none-any.whl

Download URL django_thumbor-0.6.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f65f4f3217bb896e9726c65d7b0bd1e13cf6e40e69c2f512c213d360e6764ba6
BLAKE2b-256 checksum
How to use checksums
265a7dd8e139de6607aae0be1e9fa52d075d7378236c6ae772d831222e018313
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Security for django-thumbor 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page