Skip to main content

Thumbnail maker for Django

Project description

https://travis-ci.org/infinityxxx/django-thumbnail-maker.svg?branch=master https://coveralls.io/repos/infinityxxx/django-thumbnail-maker/badge.png?branch=master https://badge.fury.io/py/django-thumbnail-maker.svg

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 anywhere after 'sorl.thumbnail' app (assume you already installed sorl-thumbnail):

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.comments',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.contenttypes',
    ...
    'sorl.thumbnail',
    ...
    '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.fields 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-thumbnail-maker-0.0.6.tar.gz (560.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

django_thumbnail_maker-0.0.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

django_thumbnail_maker-0.0.6-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-thumbnail-maker-0.0.6.tar.gz.

File metadata

  • Download URL: django-thumbnail-maker-0.0.6.tar.gz
  • Upload date:
  • Size: 560.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for django-thumbnail-maker-0.0.6.tar.gz
Algorithm Hash digest
SHA256 cc355e988b32f9e90a72ef1fd20c9bc25e483324781115e689031cabadd41edf
MD5 622df31d031f33fc8379d0e5ca281e94
BLAKE2b-256 3652b5d063e8002e79bda6802d3f17b581e3fd1c9a27592d4abae1f52a5ad922

See more details on using hashes here.

File details

Details for the file django_thumbnail_maker-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: django_thumbnail_maker-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for django_thumbnail_maker-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ec67c1fff671734dd491baba1a7d11b6e6ec9ed743315c0870996ea20d79fe18
MD5 c4b5fc042bb056e52cb29214d43dacc1
BLAKE2b-256 bfc16d05e4345852024409b2926fc684914a5a927f2364c5f2906e8b7cb6bbe9

See more details on using hashes here.

File details

Details for the file django_thumbnail_maker-0.0.6-py2.py3-none-any.whl.

File metadata

  • Download URL: django_thumbnail_maker-0.0.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for django_thumbnail_maker-0.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 faa6e1427824cf83299a93da3481e04d5baf4fd7f4b80b75a16d7704d9eccb3c
MD5 7d4bdd33100094c5666ec6aaf2625143
BLAKE2b-256 fb05be1af8d018e17a3d921e91e12a682a076ce874f73c75a08ebb216d506c0c

See more details on using hashes here.

Supported by

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