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' mymodel.imagefield.name sizes='200x0,400x0' %}
<picture>
{% for source in mythumb %}
    <source
        srcset="{{ source.url_2x }} 2x, {{ source.url }} 1x"
        {% if not forloop.last %}media="(max-width: {{ source.viewport.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.

You can also pass the viewport size in addition to the requested thumbnail size:

{% load ultimatethumb_tags %}
{% ultimatethumb 'mythumb' 'static:img/logo.jpg' sizes='400x0:600x0' %}
<img src="{{ mythumb.0.url }}" />

This will set the thumbnail.viewport.width to 600.

If you want so save some characters, you might short cut the sizes by leaving out the “x0” for the auto’ed dimesion.

{% load ultimatethumb_tags %}
{% ultimatethumb 'mythumb' 'static:img/logo.jpg' sizes='400:600' %}
<img src="{{ mythumb.0.url }}" />

The sizes are now the same as if you would use sizes=’400x0,600x0’.

Options

You can pass some options to the thumbnail tag:

  • upscale: Configures if the input should be upscaled if requested sizes are larger than source.

  • retina: Option to enable retina support (by providing both url and url_2x)

  • crop: Deside if images should be cropped if requested sizes doesn’t fit source aspect ratio.

  • quality: Configures quality for image compression

  • pngquant: Configures the pngquant compression factor

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.6.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

django_ultimatethumb-0.6.0-py2.py3-none-any.whl (13.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-ultimatethumb-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5459c0a042d36bb065696d85bc7ac9f089e34bfb914e543fa3d87096441552ed
MD5 6c8fad8082ec372768bd23ad3b0b2cfb
BLAKE2b-256 88ab6ce7eeeb42d97c5d11799bceaa856926c77c20d4a7e98be4af16debe8c31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ultimatethumb-0.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23922c737b16bb41f9e5eae992b26c751f8f9ef292e8535a3630104af817254d
MD5 bc3ccbfd6c8f2e54e7eac5aaf3901eb4
BLAKE2b-256 f84ddbd716f150192c22fc574d36fbbc6f2f9e00de976501e2e5b8e7fd8ed686

See more details on using hashes here.

Supported by

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