GitXplorerGitXplorer
c

sorl-thumbnail-async

public
22 stars
15 forks
2 issues

Commits

List of commits on branch master.
Unverified
023d20aac79090a691d563dc26f558bb87239811

Merge pull request #9 from dionysio/master

cchhantyal committed 8 years ago
Unverified
1dc9ed95daaa59475ddb7dd5edeae5972ce89632

added app config for 1.10 compatibility

ddionysio committed 8 years ago
Unverified
4beea325f2b9684ba208242b63690d63ec4db8f3

replace pil with pillow :)

committed 11 years ago
Unverified
5b47e53557b8287e31ea86445530bab9f78be149

bump version number to 0.6.0

committed 11 years ago
Unverified
66eae8a6d3881254004e1eae8974e12822fd5495

add Python 3 classifier in setup.py

committed 11 years ago
Unverified
1d57486a50e907a0293091a0eec6cf55da76d319

replace iteritems with items() for both Py2 and 3 support

committed 11 years ago

README

The README file for this repository.

sorl-thumbnail-async

Asynchronous thumbnailing app in django with remote storages like S3. This is modifications of some parts of sorl-thumbnail, which is a bit slow when used with remote storages.

  • Celery is used to create thumbnail asynchronously.
  • Thumbnails are pregenerated and cached.
  • Thumbnail sizes and options are specified in one place (your settings file).

Install

pip install sorl-thumbnail-async

Add 'thumbnail' to your INSTALLED_APPS.

Dependencies

pip install django

pip install django-celery

pip install pillow

pip install sorl-thumbnail

Usage

In your settings.py add an option called THUMBNAIL_OPTIONS_DICT, defining all your thumbnail sizes:

THUMBNAIL_OPTIONS_DICT = {
        'small': {
                'geometry': '140x140',
                'crop': 'center'
        }
    }

In your models, use thumbnail.models.AsyncThumbnailMixin as a baseclass. Make sure that your model inherits from AsyncThumbnailMixin first. This will call celery task on save(), and create one or more thumbnails from the specified image field. Use class variable image_field_name to configure the field that contains the image. Defaults to picture.

Example:

from django.db import models

from sorl import thumbnail
from thumbnail.models import AsyncThumbnailMixin


class Book(AsyncThumbnailMixin, models.Model):
    image_field_name = 'cover_image'

	title = models.CharField(blank=False, max_length=255, db_index=True)
    cover_image = thumbnail.ImageField(upload_to='books/')

In templates:

{% load thumbnail_tags %}
{% thumbnail book.cover_image small as im %}
<img src"{{ im.url }}">
{% endthumbnail %}

In python code:

from thumbnail import get_thumbnail

book = Book.objects.get(title='Life of Pi')
thumbnail_url = get_thumbnail(book.cover_image, 'small').url

Settings

You can add as many sizes and option as needed. It is a python dictionary.

THUMBNAIL_OPTIONS_DICT = {
        'small': {
                'geometry': '140x140',
                'crop': 'center'
        }
    }

NOTE: sorl-thumbnail-async registers its own THUMBNAIL_BACKEND:

THUMBNAIL_BACKEND = 'sorl-thumbnail-async.thumbnail.backend.AsyncThumbnailBackend'

Bitdeli Badge