Django Standarized Image Field
Project description
Django Standarized Image Field
Django Field that implement the following features:
Django-Storages compatible (S3)
Resize images to different sizes
Access thumbnails on model level, no template tags required
Preserves original image
Allow image deletion
Rename files to a standardized name (using a callable upload_to)
Installation
Install latest PIL - there is really no reason to use this package without it
easy_install django-stdimage
or
pip django-stdimage
Put ‘stdimage’ in the INSTALLED_APPS
Usage
Import it in your project, and use in your models.
Example:
from stdimage import StdImageField class MyClass(models.Model): # works as ImageField image1 = StdImageField(upload_to='path/to/img') # can be deleted through admin image2 = StdImageField(upload_to='path/to/img', blank=True) # creates a thumbnail resized to maximum size to fit a 100x75 area image3 = StdImageField(upload_to='path/to/img', variations={'thumbnail': (100, 75)}) # creates a thumbnail resized to 100x100 croping if necessary image4 = StdImageField(upload_to='path/to/img', variations={'thumbnail': (100, 100, True}) # all previous features in one declaration image_all = StdImageField(upload_to='path/to/img', blank=True, variations={'large': (640, 480), 'thumbnail': (100, 100, True)})
For using generated thumbnail in templates use “myimagefield.thumbnail”. Example:
<a href="{{ object.myimage.url }}"><img alt="" src="{{ object.myimage.thumbnail.url }}"/></a>
About image names
By default StdImageField stores images without modifying the file name. If you want to use more consistent file names you can use the build in upload functions. Example:
from stdimage import StdImageField, UPLOAD_TO_CLASS_NAME, UPLOAD_TO_CLASS_NAME_UUID, UPLOAD_TO_UUID from functools import partial class MyClass(models.Model) # Gets saved to MEDIA_ROOT/myclass/#FILENAME#.#EXT# image1 = StdImageField(upload_to=UPLOAD_TO_CLASS_NAME) # Gets saved to MEDIA_ROOT/myclass/pic.#EXT# image2 = StdImageField(upload_to=partial(UPLOAD_TO_CLASS_NAME, name='pic')) # Gets saved to MEDIA_ROOT/images/#UUID#.#EXT# image3 = StdImageField(upload_to=partial(UPLOAD_TO_UUID, path='images')) # Gets saved to MEDIA_ROOT/myclass/#UUID#.#EXT# image4 = StdImageField(upload_to=UPLOAD_TO_CLASS_NAME_UUID)
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 Distribution
File details
Details for the file django-stdimage-0.5.0.tar.gz
.
File metadata
- Download URL: django-stdimage-0.5.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bdbabfdd394ac5652ec5b579a8e748a61e22082b169fa5721ddd925169657f6 |
|
MD5 | 24115097fa429857f0bcf6ec9865bf5a |
|
BLAKE2b-256 | b3ffb3eb8f63a2b1e06df34da3b218f3b271ccc01d8696a24165b51ac7c12321 |
Provenance
File details
Details for the file django-stdimage-0.5.0.macosx-10.9-intel.exe
.
File metadata
- Download URL: django-stdimage-0.5.0.macosx-10.9-intel.exe
- Upload date:
- Size: 68.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 025601f017e730f4d959bd3b2dcb4483e15a52f45918196ee1fa5bf8435f7957 |
|
MD5 | 03c3fb94014503f1dfc3fad02fa65e7d |
|
BLAKE2b-256 | 9377a92e403f37d034a0019644b3121f7fd2ed103821eef31173b8be38ff8da4 |