Django-thumbs
The easiest way to create thumbnails for your images with Django. Works with any StorageBackend.
Features
Easy to integrate in your code (no database changes, works as an ImageField)
Works perfectly with any StorageBackend
Generates thumbnails after image is uploaded into memory
Deletes thumbnails when the image file is deleted
Provides easy access to the thumbnails’ URLs (similar method as with ImageField)
Requirements
Python 2.5+
Django 1.1+
PIL (Python Image Library)
Getting It
You can get Django-Thumbs by using pip or easy_install:
$ pip install django-thumbs or $ easy_install django-thumbs
If you want to install it from source, grab the git repository from github and run setup.py:
$ git clone git://github.com/skitoo/django-thumbs.git $ cd django-thumbs $ python setup.py install
Installation
Import it in your models.py and replace ImageField with ImageWithThumbsField in your model
Add a sizes attribute with a list of sizes you want to use for the thumbnails
Make sure your have defined MEDIA_URL in your settings.py
That’s it!
Working example
from django.db import models
from django_thumbs.db.models import ImageWithThumbsField
class Person(models.Model):
photo = ImageWithThumbsField(upload_to='images', sizes=((125,125),(200,200)))
second_photo = ImageWithThumbsField(upload_to='images')
In this example we have a Person model with 2 image fields.
You can see the field second_photo doesn’t have a sizes attribute. This field works exactly the same way as a normal ImageField.
The field photo has a sizes attribute specifying desired sizes for the thumbnails. This field works the same way as ImageField but it also creates the desired thumbnails when uploading a new file and deletes the thumbnails when deleting the file.
With ImageField you retrieve the URL for the image with: someone.photo.url With ImageWithThumbsField you retrieve it the same way. You also retrieve the URL for every thumbnail specifying its size: In this example we use someone.photo.url_125x125 and someone.photo.url_200x200 to get the URL of both thumbnails.
Uninstall
At any time you can go back and use ImageField again without altering the database or anything else. Just replace ImageWithThumbsField with ImageField again and make sure you delete the sizes attribute. Everything will work the same way it worked before using django-thumbs. Just remember to delete generated thumbnails in the case you don’t want to have them anymore.
Metadata
Release files for django-thumbs 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-thumbs-0.4.tar.gz | 6.1 kB | Without provenance | Details for django-thumbs-0.4.tar.gz |
Release files / django-thumbs-0.4.tar.gz
| Download URL | django-thumbs-0.4.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59d55c131c8953a485e9e8315dc8fc65761731f98d5c73e703e7a4fbce01b8c8
|
|
BLAKE2b-256 checksum How to use checksums |
0804416cdeccc61028ea8e4cf2a8df075e6bcd42c26fb9e01c310f2c9210c29a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-thumbs 0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.