Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chhantyal/sorl-thumbnail-async
Asynchronous thumbnailing app in django with remote storages like S3
https://github.com/chhantyal/sorl-thumbnail-async
django django-application python sorl-thumbnail
Last synced: about 1 month ago
JSON representation
Asynchronous thumbnailing app in django with remote storages like S3
- Host: GitHub
- URL: https://github.com/chhantyal/sorl-thumbnail-async
- Owner: chhantyal
- License: bsd-3-clause
- Created: 2013-07-05T14:15:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-09-23T22:24:19.000Z (about 8 years ago)
- Last Synced: 2024-09-30T10:42:47.366Z (about 2 months ago)
- Topics: django, django-application, python, sorl-thumbnail
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 21
- Watchers: 3
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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 AsyncThumbnailMixinclass 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 %}
{% 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').urlSettings
--------
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'
[sorl-thumbnail]: https://github.com/mariocesar/sorl-thumbnail
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/chhantyal/sorl-thumbnail-async/trend.png)](https://bitdeli.com/free "Bitdeli Badge")