Generate thumbnails of anything.
Project description
What is django-ultimatethumb
django-ultimatethumb is another Django library for generating thumbnails but has some advantages:
Thumbnails are not generated when the templatetag is called. Instead, images are generated on demand when they are requested by the browser. This can lead to a major speedup of your page response times.
Thumbnails can be generated from static files too (for example to downscale retina-optimized images and therefore reducing traffic).
Generate multiple thumbnail sizes at once for use in picture html tags with multiple sources (e.g. with media queries).
Quick start
To install django-ultimatethumb just use your preferred Python package installer:
$ pip install django-ultimatethumb
Add some stuff to your Django settings
INSTALLED_APPS = (
# some other apps
'ultimatethumb',
)
# This is the path where the generated thumbnail files are cached.
ULTIMATETHUMB_ROOT = '/filesystem/path/to/thumbnails/'
# This is the base url for your thumbnails
ULTIMATETHUMB_URL = '/thumbnails/'
Next, add the django-ultimatethumb urls to your urls.py
urlpatterns += patterns(
'',
url(
r'^{0}/'.format(settings.ULTIMATETHUMB_URL.strip('/')),
include('ultimatethumb.urls')
),
To use django-ultimatethumb in your templates, just load the templatetags and call the ultimatethumb tag with proper parameters:
{% load ultimatethumb_tags %}
{% ultimatethumb 'mythumb' mymodel.imagefield.name sizes='400x0,200x0' %}
<picture>
{% for source in mythumb %}
<source
srcset="{{ source.url_2x }} 2x, {{ source.url }} 1x"
{% if not forloop.last %}media="(max-width: {{ source.size.width }}px)"{% endif %}
/>
{% if forloop.last %}<img src="{{ source.url }}" />{% endif %}
{% endfor %}
</picture>
This gives you a full-featured picture tag including multiple sources with media queries for different browser sizes and also provides retina images.
You can also use django-ultimatethumb in a much simpler way:
{% load ultimatethumb_tags %}
{% ultimatethumb 'mythumb' mymodel.imagefield.name sizes='400x0' %}
<img src="{{ mythumb.0.url }}" />
To resize static images, just prefix the path with static:, for example:
{% load ultimatethumb_tags %}
{% ultimatethumb 'mythumb' 'static:img/logo.jpg' sizes='400x0' %}
<img src="{{ mythumb.0.url }}" />
There are many other options/parameters to pass to the templatetag. Please refer to the codebase until the documentation is more complete.
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 django-ultimatethumb-0.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b31a81436115dae4dca5568de1ca8357b28d0e79c7feb264d7fe2e6c3b4d0ce |
|
MD5 | 72bc1c20d0416e69042d342d72fb592e |
|
BLAKE2b-256 | af26a6db9ddfbdc176f530909464ffa8aeb5a15a9a4c59640fbe9d7169a6cc76 |
Hashes for django_ultimatethumb-0.4.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a81d1ed57c5f71af7c0f929f3715b848ac2d9ac7700a4b7ec0d9ec3422057a10 |
|
MD5 | 27f297cfa8f806efd9469c2180b2d008 |
|
BLAKE2b-256 | f4e45ab2323009909cff8369509268d75e1b2db6b11d72bacd3a193ae5aad60d |