Skip to main content

Thumbnails for Django

Project description

travis sorl-thumbnail on PyPI coveralls

Thumbnails for Django.

Features at a glance

  • Support for Django 1.11, 2.0, and 2.1 following the Django supported versions policy

  • Python 3 support

  • Storage support

  • Pluggable Engine support for Pillow, ImageMagick, PIL, Wand, pgmagick, and vipsthumbnail

  • Pluggable Key Value Store support (cached db, redis, and dynamodb by AWS)

  • 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

Jazzband

This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines.

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 or Gitter.

For releases updates and more in deep development discussion use our mailing list in Google Groups.

Tests

The tests should run with tox and pytest. Running tox will run all tests for all environments. However, it is possible to run a certain environment with tox -e <env>, a list of all environments can be found with tox -l. These tests require the dependencies of the different engines defined in the documentation. It is possible to install these dependencies into a vagrant image with the Vagrantfile in the repo.

User Support

If you need help using sorl-thumbnail browse http://stackoverflow.com/questions/tagged/sorl-thumbnail and posts your questions with the sorl-thumbnail tag.

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

Using in combination with other thumbnalers

Alternatively, you load the templatetags by {% load sorl_thumbnail %} instead of traditional {% load thumbnail %}. It’s especially useful in projects that do make use of multiple thumbnailer libraries that use the same name (thumbnail) for the templatetag module:

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

Frequently asked questions

Is so slow in Amazon S3 !

Possible related to the implementation of your Amazon S3 Backend, see the issue #351 due the storage backend reviews if there is an existing thumbnail when tries to generate the thumbnail that makes an extensive use of the S3 API

A fast workaround if you are not willing to tweak your storage backend is to set:

THUMBNAIL_FORCE_OVERWRITE = True

So it will avoid to overly query the S3 API.

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

sorl-thumbnail-12.5.0.tar.gz (533.5 kB view details)

Uploaded Source

Built Distribution

sorl_thumbnail-12.5.0-py2.py3-none-any.whl (41.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sorl-thumbnail-12.5.0.tar.gz.

File metadata

  • Download URL: sorl-thumbnail-12.5.0.tar.gz
  • Upload date:
  • Size: 533.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/36.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

File hashes

Hashes for sorl-thumbnail-12.5.0.tar.gz
Algorithm Hash digest
SHA256 8dfe5fda91a5047d1d35a0b9effe7b000764a01d648e15ca076f44e9c34b6dbd
MD5 8c2945b56a7ed324d276094545774e9b
BLAKE2b-256 50ae632239910bc88c2c27615ed9b8f725844db67278da8a487dafaf024fd2aa

See more details on using hashes here.

File details

Details for the file sorl_thumbnail-12.5.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sorl_thumbnail-12.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/36.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

File hashes

Hashes for sorl_thumbnail-12.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d9e3f018d19293824803e4ffead96b19dfcd44fa7987cea392f50436817bef34
MD5 aae414a4a6318134d2b0784a13ca901e
BLAKE2b-256 58d110c1174b718781ad835f0ec5a0751ca1fcd3ba2277a9328d635f270edadf

See more details on using hashes here.

Supported by

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