Skip to main content

Thumbnails for Django

Project description

travis pypi coveralls

Thumbnails for Django.

Features at a glance

  • Support for Django 1.4, 1.5 and 1.6
  • Python 3 support (for Django 1.5 and Django 1.6)
  • Storage support
  • Pluggable Engine support for Pillow, ImageMagick, PIL, Wand and pgmagick
  • Pluggable Key Value Store support (cached db, redis)
  • Pluggable Backend support
  • Admin integration with possibility to delete
  • Dummy generation (placeholders)
  • Flexible, simple syntax, generates no html
  • ImageField for model that deletes thumbnails
  • CSS style cropping options
  • Back smart cropping, and remove borders from the images when cropping
  • Margin calculation for vertical positioning
  • Alternative resolutions versions of a thumbnail

Read more in the documentation (latest version)

Developers

Feel free to create a new Pull request if you want to propose a new feature. If you need development support or want to discuss with other developers join us in the channel #sorl-thumnbnail at freenode.net

irc://irc.freenode.net/#sorl-thumbnail

Or join us in Gitter.im

https://gitter.im/mariocesar/sorl-thumbnail

How to Use

Get the code

Getting the code for the latest stable release use ‘pip’.

$ pip install sorl-thumbnail

Install in your project

Then register ‘sorl.thumbnail’, 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',

    'sorl.thumbnail',
)

Templates Usage

All of the examples assume that you first load the thumbnail template tag in your template.:

{% load thumbnail %}

A simple usage.

{% thumbnail item.image "100x100" crop="center" as im %}
    <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}

See more examples in the section Template examples in the Documentation

Model Usage

Using the ImageField that automatically deletes references to itself in the key value store and its thumbnail references and the thumbnail files when deleted.:

from django.db import models
from sorl.thumbnail import ImageField

class Item(models.Model):
    image = ImageField(upload_to='whatever')

See more examples in the section Model examples in the Documentation

Low level API

You can use the ‘get_thumbnail’:

from sorl.thumbnail import get_thumbnail
from sorl.thumbnail import delete

im = get_thumbnail(my_file, '100x100', crop='center', quality=99)
delete(my_file)

See more examples in the section Low level API examples in the Documentation

Project details


Release history Release notifications

History Node

12.4.1

History Node

12.4a1

History Node

12.3

History Node

12.2

History Node

12.1c

This version
History Node

11.12.1b

History Node

11.12

History Node

11.09.1

History Node

11.09

History Node

11.05.2

History Node

11.05.1

History Node

11.05

History Node

11.04

History Node

11.01

History Node

10.12.1

History Node

10.12

History Node

10.12-beta4

History Node

10.12-beta3

History Node

10.12-beta2

History Node

10.12-beta

History Node

10.12-alpha

History Node

3.2.5

History Node

3.2.4

History Node

3.2.3

History Node

3.2.2

History Node

3.2.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
sorl_thumbnail-11.12.1b-py27-none-any.whl (36.7 kB) Copy SHA256 hash SHA256 Wheel 2.7 Mar 28, 2014
sorl_thumbnail-11.12.1b-py33-none-any.whl (36.7 kB) Copy SHA256 hash SHA256 Wheel 3.3 Mar 28, 2014
sorl-thumbnail-11.12.1b.tar.gz (62.3 kB) Copy SHA256 hash SHA256 Source None Mar 28, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page