Skip to main content

Easy thumbnails for Django

Project description

A powerful, yet easy to implement thumbnailing application for Django.

Below is a quick summary of usage. For more comprehensive information, view the full documentation online or the peruse the project’s docs directory.

Installation

Run pip install easy_thumbnails, or for the in-development version run pip install easy_thumbnails==dev.

Add easy_thumbnails to your INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'easy_thumbnails',
)

If you have South installed then run manage.py migrate easy_thumbnails, otherwise just run manage.py syncdb.

Example usage

Thumbnail options can be predefined in settings.THUMBNAIL_ALIASES or just specified in the template or Python code when run.

Using a predefined alias

Given the following setting:

THUMBNAIL_ALIASES = {
    '': {
        'avatar': {'size': (50, 50), 'crop': True},
    },
}

Template:

{% load thumbnail %}
<img src="{{ profile.photo|thumbnail_url:'avatar' }}" alt="">

Python:

from easy_thumbnails.files import get_thumbnailer
thumb_url = get_thumbnailer(profile.photo)['avatar'].url

Manually specifying size / options

Template:

{% load thumbnail %}
<img src="{% thumbnail profile.photo 50x50 crop %}"

Python:

from easy_thumbnails.files import get_thumbnailer
options = {'size': (100, 100), 'crop': True}
thumb_url = get_thumbnailer(profile.photo).get_thumbnail(options).url

Fields

You can use ThumbnailerImageField (or ThumbnailerFileField) for easier access to retrieve or generate thumbnail images, or to .

For example:

from easy_thumbnails.fields import ThumbnailerImageField

class Profile(models.Model):
    user = models.OneToOneField('auth.User')
    photo = ThumbnailerImageField(upload_to='photos', blank=True)

Accessing the field’s predefined alias in a template:

{% load thumbnail %}
<img src="{{ profile.photo.avatar.url }}" alt="">

Accessing the field’s predefined alias in Python code:

thumb_url = profile.photo['avatar'].url

Thumbnail options

crop

Before scaling the image down to fit within the size bounds, it first cuts the edges of the image to match the requested aspect ratio.

Use crop="smart" to try to keep the most interesting part of the image,

Use crop="0,10" to crop from the left edge and a 10% offset from the top edge. Crop from a single edge by leaving dimension empty (e.g. crop=",0"). Offset from the right / bottom by using negative numbers (e.g., crop=”-0,-10”).

Often used with the upscale option, which will allow enlarging of the image during scaling.

quality=XX

Changes the quality of the output JPEG thumbnail. Defaults to 85.

In Python code, this is given as a separate option to the get_thumbnail method rather than just alter the other

Other options

Valid thumbnail options are determined by the “thumbnail processors” installed.

See the reference documentation for a complete list of options provided by the default thumbnail processors.

Changes

1.1

  • Added a way to avoid generating thumbnails if they don’t exist already (with a signal to deal with them elsewhere).

  • Added a thumbnailer_passive filter to allow templates to use the non-generating thumbnails functionality when dealing with aliases.

1.0.3

  • Changed the exception to catch from 1.0.2 to IOError.

1.0.2

  • Catch an OSError exception when trying to get the EXIF data of a touchy image.

1.0.1

  • Fix a Django 1.2 backwards incompatibility in easy_thumbnails.conf

  • Introduced a thumbnail_created signal.

1.0

  • Introduction of aliased thumbnails.

  • Start of sane versioning numbers.

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

easy-thumbnails-1.1.tar.gz (51.9 kB view details)

Uploaded Source

File details

Details for the file easy-thumbnails-1.1.tar.gz.

File metadata

File hashes

Hashes for easy-thumbnails-1.1.tar.gz
Algorithm Hash digest
SHA256 3b4078d85e399dc725ac7a939fa20e6c407925dd289627864ba7b72d4f4098f0
MD5 a874b3698968c2b5c9dbb6dcb7285741
BLAKE2b-256 091114c04aaa90d4f7035e680188e8ffcba956c2d229e989713c2cf19c6eec9d

See more details on using hashes here.

Provenance

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