diff --git a/exif_info/README.md b/exif_info/README.md new file mode 100644 index 0000000..87c218f --- /dev/null +++ b/exif_info/README.md @@ -0,0 +1,69 @@ +EXIF Info +================== + +* Retrieve EXIF informations from pictures + +##How to Use + +1. Install the PIL (Python Imaging Library) libraries, please refer to http://pythonware.com/products/pil/ or your OS manual for instructions. +2. This plugin is an extension to the Gallery plugin, so first install it, and refer to its README for usage instructions. +3. Add 'exif_info' to the plugin list. + +If you want, you can also specify in your configuration: + + EXIF_INFO_DEFAULT = True/False + +To set whether or not to retrieve by default the EXIF informations from your pictures. This setting can be overriden on a per article/album basis. + +###Articles + +Override on a per article/post basis the default behaviour by adding the following: + + exifinfo: "True" + +or + + exifinfo: "False" + +###Gallery Page + +At this time the Gallery page is *not* supported. + +##Examples + +###article.html + + {% if article.album %} + {% for image in article.galleryimages %} + {% if article.galleryexif and article.galleryexif.get(image) %} + + {% if article.galleryexif.get(image).get("Model") %} + + {% endif %} + {% if article.galleryexif.get(image).get("LensModel") %} + + {% endif %} + + {% if article.galleryexif.get(image).get("ISOSpeedRatings") %} + + {% endif %} + {% if article.galleryexif.get(image).get("FocalLength") %} + + {% endif %} + {% if article.galleryexif.get(image).get("FNumber") %} + + {% endif %} + {% if article.galleryexif.get(image).get("ExposureTime") %} + + {% endif %} + +
{{article.galleryexif.get(image).get("Model")}}
{{article.galleryexif.get(image).get("LensModel")}}
{{article.galleryexif.get(image).get("ISOSpeedRatings")}}{{article.galleryexif.get(image).get("FocalLength")}}mmf/{{article.galleryexif.get(image).get("FNumber")}}{{article.galleryexif.get(image).get("ExposureTime")}}
+ {% endif %} + {% endfor %} + {% endif %} + +##Reasoning + +This was developped as an external plugin, instead of adapting the Gallery plugin because this relies on the PIL libraries to be installed, and working. + +As this set of library may - or not - be available on a given platform, it seemed unreasonable to limit the Gallery plugin to the systems where it is. \ No newline at end of file diff --git a/exif_info/__init__.py b/exif_info/__init__.py new file mode 100644 index 0000000..e375362 --- /dev/null +++ b/exif_info/__init__.py @@ -0,0 +1 @@ +from .exif_info import * diff --git a/exif_info/exif_info.py b/exif_info/exif_info.py new file mode 100644 index 0000000..edac303 --- /dev/null +++ b/exif_info/exif_info.py @@ -0,0 +1,86 @@ +import os +import re +from pelican import signals +from PIL import Image +from PIL.ExifTags import TAGS + +def get_exif_data(fname): + """Get embedded EXIF data from an image file.""" + exif = {} + ret = {} + try: + img = Image.open(fname) + if hasattr( img, '_getexif' ): + exifinfo = img._getexif() + if exifinfo != None: + for tag, value in exifinfo.items(): + decoded = TAGS.get(tag, tag) + ret[decoded] = value + except IOError: + print 'IOERROR ' + fname + + #print ret + # Keep and format the most interesting fields + for tag in ret: + if tag == "DateTimeOriginal": + exif[tag] = ret[tag] + if tag == "Model": + exif[tag] = ret[tag] + if tag == "LensModel": + exif[tag] = ret[tag] + if tag == "ISOSpeedRatings": + exif[tag] = ret[tag] + if tag == "FocalLength": + exif[tag] = "{:2.1f}".format(float(ret[tag][0]) / float(ret[tag][1])) + if tag == "FNumber": + exif[tag] = "{:2.1f}".format(float(ret[tag][0]) / float(ret[tag][1])) + if tag == "ExposureTime": + exif[tag] = str(ret[tag][0]) + "/" + str(ret[tag][1]) + + return exif + + +def add_exif_post(generator): + get_exif = generator.settings.get('EXIF_INFO_DEFAULT') + if get_exif == None: + get_exif = True; + + contentpath = generator.settings.get('PATH') + gallerycontentpath = os.path.join(contentpath,'images/gallery') + + for article in generator.articles: + if 'exifinfo' in article.metadata.keys(): + if article.metadata.get('exifinfo'): + # Ignore anything which is not a capitalization variation of + # true/false + if article.metadata.get('exifinfo').lower() == "true": + get_exif = True; + if article.metadata.get('exifinfo').lower() == "false": + get_exif = False; + + if get_exif: + if 'gallery' in article.metadata.keys(): + album = article.metadata.get('gallery') + galleryexif = dict() + + articlegallerypath=os.path.join(gallerycontentpath, album) + + # If the gallery has not yet been generated generate one + if article.metadata.get('galleryimages'): + galleryimages = article.metadata.get('galleryimages'); + else: + galleryimages = [] + if(os.path.isdir(articlegallerypath)): + for i in os.listdir(articlegallerypath): + if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)): + galleryimages.append(i) + + # Retrieve the EXIF informations for all the images + for img in galleryimages: + galleryexif[img] = get_exif_data(articlegallerypath + "/" + img) + + article.galleryexif = galleryexif + + +def register(): + signals.article_generator_finalized.connect(add_exif_post) \ No newline at end of file