jdriscoll / django-imagekit

Automates image processing for Django models. Resize, process and cache multiple versions of your image files. Access newly created files with a standard API. Supports alternate storage schemes such as Amazon S3.

Clone this repository (size: 135.6 KB): HTTPS / SSH
$ hg clone http://hg.driscolldev.com/django-imagekit

ImageModel

The ImageModel abstract base class is the core of ImageKit. By inheriting from this class your models are augmented with a new accessor property for each image specification you define. These accessors expose a similar API to the Django ImageField, allowing you to easily access image URLs, files and dimensions.

Lets assume we've defined the following image specification and configured our model to use it in our IKOptions inner class:

1
2
3
4
5
6
7
8
9
from imagekit.specs import ImageSpec 
from imagekit import processors 

class ResizeDisplay(processors.Resize):
    width = 600 

class Display(ImageSpec):
    increment_count = True
    processors = [ResizeDisplay]

We would now be able to access this processed image using the following API:

PropertyReturn TypeDescription
instance.display.urlStringReturns the URL of the image relative to MEDIA_URL
instance.display.fileFile objectReturns the image file as a file-like object
instance.display.imagePIL ImageReturns the image as a PIL Image
instance.display.widthIntegerReturns the image width
instance.display.heightIntegerReturns the image height

This revision is from 2010-08-26 01:05