Templatetags for thumbnail generation, with automatic rotation based on EXIF.Orientation.
Project description
Version : 0.1.0 Author : Thomas Weholt <thomas@weholt.org> License : GPL v3.0 WWW : https://bitbucket.org/weholt/django-photofile Status : Experimental
About
Templatetags for thumbnail generation, supports automatic rotation based on EXIF.Orientation.
Planned routines for metadata handling (EXIF/IPTC/XMP).
How
<img src=”{% generate_thumbnail imagefile 100x100 crop %}”/>
Provides a templatetag called generate_thumbnail which takes two or three parameters:
Param #1 : an object (imagefile), like a model instance, with a property/field called unique_filename, complete_filename or filename. Photofile will check in that order.
Param #2: resolution, specified as <width>x<height>, like 320x280.
Param #3: optional “crop” - which will enforce cropping of the photo.
The thumbnail will be written in a dir called “thumbs” in your STATICFILES_DIRS or STATIC_ROOT. If no dir exists called thumbs, it will be created.
The generated thumbnail will be named <filename>_<width>x<height>.<extension>. When cropping is used it will be named <filename>_<width>x<height>_crop.<extension>. For instance, thumbnail for test.jpg in resolution 200x300 will be named test_200x300.jpg.
Photofile will try to use caching if enabled, but it caches the url to the thumbnail, not the image itself so it’s not very efficient yet.
NB! It’s highly recommended to have some way of ensuring that the filename given to photofile is unique. That’s why it will look for a property called unique_filename first.
Why another thumbnail app for django?
I’ve looked at sorl-thumbnail and others, and initially I wanted to use an existing project, but none of them supported automatic rotation based on EXIF.Orientation.
Installation
Alternative a) pip install django-photofile. Alternative b) download source, unpack and do python setup.py install. Alternative c) hg clone https://bitbucket.org/weholt/django-photofile and do python setup.py install.
Usage
In settings.py: 1. Add ‘photofile’ to your INSTALLED_APPS. 2. Set up caching if you want. 3. Add a dir to your STATICFILES_DIRS or set STATIC_ROOT.
In your template: {% load photofile_tags %}
<img src=”{% generate_thumbnail imagefile 200x300 %}”/> or <img src=”{% generate_thumbnail imagefile 100x100 crop %}”/>
Where imagefile is an object with at a property/field called: a) unique_filename or b) complete_filename or c) filename
Resolution is specified as <width>x<height>, for instance 640x480 and if you want to crop the photo add crop as shown in the example over.
Requirements
django
PIL
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
File details
Details for the file Photofile-0.1.0.zip
.
File metadata
- Download URL: Photofile-0.1.0.zip
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e0c4b47ef558be1b963462efdaee64d73633d2873dd456d0ebe4d36c04220e4 |
|
MD5 | e6f34c2a59156cb67e235d29069f7c0c |
|
BLAKE2b-256 | 4592870d2cb64b835693b1a1844a6530cf7bb48a0ba96f18e40a58565bbfa005 |