Skip to main content

Generate thumbnails of anything.

Project description

https://badge.fury.io/py/django-ultimatethumb.png https://travis-ci.org/moccu/django-ultimatethumb.svg?branch=master https://coveralls.io/repos/moccu/django-ultimatethumb/badge.svg https://readthedocs.org/projects/django-ultimatethumb/badge/?version=latest

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' image.file.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' image.file.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ultimatethumb-0.3.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_ultimatethumb-0.3.0-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-ultimatethumb-0.3.0.tar.gz.

File metadata

File hashes

Hashes for django-ultimatethumb-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4a62c00bb0029ae147dda8e8640769bc3a28f413dcecad2ce06a15d24bdd395a
MD5 cc298e9336b2086482fff6f94986db93
BLAKE2b-256 e02225fc932ac88b622956a16574675ed6143cd343cd2563111b4dd364cd03b5

See more details on using hashes here.

File details

Details for the file django_ultimatethumb-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_ultimatethumb-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1ee92cabaa6ef0ee324a7ebf4eaf1e4512faccc6865f1ee4a238afd9577a86fe
MD5 31680a2874e778f3e0480c4a322c5e58
BLAKE2b-256 6787f57268ae8fd04442b1629415e33bb5f5fd9322ac581f99eeef6e47d3ba63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page