Django-imageresize is an extension to the Django web framework that lets you resize images on server side just by specifying the size in the url. If you want to resize an image, foo.png
, to 100×100 you simply just use the url foo.100x100.png
which makes it very easy to create for example thumbnails.
The benefits of django-imageresize are:
- Size is specified in link only, no dependecy on django templates
- Images are resized using Imagemagick which delivers excellent quality
- Resized images are cached on disk to improve performance.
- No performance degradation after first resize if using content distribution networks like Akamai
There exists a lot of similar projects/snippets, some with plenty of more functions, but they tend to rely on the django template language which is something we wanted to avoid. Some examples:
- Fixed settings.py conflict.
- Fixed so that it is possible to scale images with no file ending
First version. Fully working, but not tested in a production environment.
Download and install Imagemagick from Imagemagick official homepage
For now you need to install from source. Download the source from GitHub’s downloads page.
In source directory run:
> easy_install .
Add the imageservice
to the installed apps in your django application’s settings.py
:
INSTALLED_APPS = ( ... 'imageservice', ... )
In same file, configure the cache root (this is where the resized images will be stored):
MEDIA_CACHE_ROOT = “/path/to/store/cached/images/”
And the max allowed size:
RESIZE_MAX_WIDTH = 2048
RESIZE_MAX_HEIGHT = 2048