Requires The mg.core.element application.
This application is responsible for handling still images in a gallery. It provides a cache of resized image files in order to provide galleries to different devices.
This is probably the most used application for a photo gallery. Here you’ll find models for storing photos, a bunch of reduced versions of the photos (in order to avoid uploading the RAW files to visitors), and some utility classes.
A photo is the authoritative model for storing pictures. All other classes only store caches of the data stored herein. From this objects, and the associated file, we can extract Exif information, thumbnails, resized photos, etc.
The file containing the original picture.
Width of the original picture.
Height of the original picture.
width/height ratio, to help find pictures by format.
max((width, height)), here for query efficiency.
Format of the original image, taken in Photo.FORMATS choices.
The side of the original picture that is the bottom of the scene. This defines the orientation of the original picture. See bottom side.
Retrieves the absolute path to saved file in spool.
Returns: | An absolute path in file system |
---|
A file where the resized photo is stored in JPEG format.
The side of the original picture used to generate the resized photo. If the bottom_side value does not match the one of the original picture, updaters will recompute the resized photo. See bottom side.
Creates a name matching the referenced element and size. This can be used as base path for saving the thumbnail file.
Returns: | A relative path string |
---|
Bottom side is a CharField where allowed values are one of D (default), B (bottom), T (top), L (left), or R (right). D is equivalent to B, except for the ExifOrientation updater.
Rehash the resized photos, if missing or in wrong orientation.
Retrieves the Exif data from photo original file, if available, and set the bottom_side field and timestamp from relevant data.
This updater only updates photos where the current value for bottom side is D. This way, if Exif information was incorrect and got overridden by the user, this updater won’t put back broken data.
In order to use these templatetags, you must use the following code in your template:
{% load mg_photo %}
This inclusion tag generates links to the relevant links for each of the photo sizes. When such link is followed:
{% prefer_size_links %}
Prefered size for photos is used by the photo_resized_get template tag.
Used template is photo/prefer_size.html. It gets a sizes variable with all the existing PhotoSize objects.
This tag retrieves a ResizedPhoto fitting the user’s preferences. Example:
{% photo_resized_get photo_element as resized %}
<img src="{{resized.file.url}}"
alt="{{photo_element.description}}"
title="{{photo_element.name}}" />
mg.media.photo provides one view. It is not directly usable to display the pictures, though.
A view used by the prefer_size_links template tag.
mg.media.photo.urls exports mg.media.photo.views.prefer_size().
mg.media.photo.urls should be included in root urls.py.
mg.media.photo registers a view to the admin site permitting change of orientation of all the photos.
Then you’ll get a (paginated) grid of all photos, with a set of links to set the correct rotation of photos. See Bottom side for more information.