Thumbnail maker for Django
Project description
Auto-generator of thumbnails for Django, using sorl-thumbnail.
Features
Auto-genarates thumbnails using sorl-thumbnail while uploading (saving) images
You can use any engines & plugins you usually use with sorl-thumbnail
The application does not replace thumbnail templatetag and you can use everything you want from sorl-thumbnail
Command to auto-generate missing thumbnails
How to Use
Get the code
Get the code for the latest stable release use pip:
$ pip install django-thumbnail-maker
Configure your project
Register 'thumbnail_maker', in the INSTALLED_APPS section of your project’s settings:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.comments', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.contenttypes', 'thumbnail_maker', )
Set up required thumb formats in THUMBNAIL_MAKER_FORMATS dictionary. Keys are the names for your formats (could be any string). Values are tuples of length 2: first element is a geometry string (used in sorl-thumbnail), second is a dictionary with options (crop, quality, padding, format, etc.):
THUMBNAIL_MAKER_FORMATS = { 'banner': ('400x300', {'crop': 'center', 'quality': 90}), '50x50': ('50x50', {}), 'any_name': ('5x277', {'padding': True}) }
You can set up THUMBNAIL_MAKER_DEBUG setting. By default it is set to False in order to pass exceptions while saving models or while generating batch of thumbnails. This setting is not required. Usage:
THUMBNAIL_MAKER_DEBUG = True
Set up your model’s field
Use ImageWithThumbnailsField and thumbs option, where thumbs is a tuple of thumb format names (keys from THUMBNAIL_MAKER_FORMATS dictionary):
from django.db import models from thumbnail_maker import ImageWithThumbnailsField class Item(models.Model): image = ImageWithThumbnailsField( upload_to='somewhere', thumbs=('banner', '50x50'), )
Templates usage
All of the examples assume that you first load the thumbnail_maker template tag in your template:
{% load thumbnail_maker %}
A simple usage:
{% usethumbnail item.image "banner" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% endusethumbnail %} {% usethumbnail item.image "50x50" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% endusethumbnail %}
You can also use string paths instead of image objects:
{% usethumbnail "dummy/image.png" "50x50" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% endusethumbnail %}
Management commands usage
Django-thumbnail-maker comes with a manage.py command to generate missing thumbs. You can use it while
./manage.py make_thumbnails <app>.<model> <field>
In case you want to make all thumbs replacing old ones, use --force option:
./manage.py make_thumbnails --force <app>.<model> <field>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django-thumbnail-maker-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3253a7d9f29a52864632e3a8b8fd9637837eb0f326a6225a554f1cd6e6757027 |
|
MD5 | d1ffaea3d8f90619f95ac0b37983811a |
|
BLAKE2b-256 | 72ba166de1cc28ea750ab0d99d96e28fdcee179761e3e4ad237c724dca205c4a |
Hashes for django_thumbnail_maker-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70a38dcac0a1d39bfd82e5694d431732bb1ec5c42455c0fee243c14c2447b8c1 |
|
MD5 | 0360fa7564f7faeb9137e71f27b799cf |
|
BLAKE2b-256 | 03ea6ffa6e5a295f09176b0707a7988ac547237c2bafd62f44eeb0aef8adefc5 |
Hashes for django_thumbnail_maker-0.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40b9bcf5b5ea03efc064dd364403b248a86b7da8a9f6626293fdd96357e22fd2 |
|
MD5 | d1dee6c46c521dd26149d6b933b948fb |
|
BLAKE2b-256 | 660e1e111861b928701084659945dac16bb5ae2de8913a0ad02ce5b819154346 |