summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-08-31 20:16:35 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-08-31 20:16:35 +0200
commitd768ed653a435c2ddd8fc0c1bfec72a0ec5e5a48 (patch)
treed9291b1c3bb8c1a81611c23a3af3369033e2bc16
parent299daf2a7f6f7e5609c82a6c69d9b12298f1d27e (diff)
downloadChimère-d768ed653a435c2ddd8fc0c1bfec72a0ec5e5a48.tar.bz2
Chimère-d768ed653a435c2ddd8fc0c1bfec72a0ec5e5a48.zip
Re-oriente picture according to exif information
-rw-r--r--chimere/feeds.py4
-rw-r--r--chimere/models.py37
-rw-r--r--debian/control5
-rw-r--r--docs/install.rst6
-rw-r--r--docs/upgrade.rst4
5 files changed, 46 insertions, 10 deletions
diff --git a/chimere/feeds.py b/chimere/feeds.py
index d5ae5ef..057fe5e 100644
--- a/chimere/feeds.py
+++ b/chimere/feeds.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# Copyright (C) 2010 Pierre Clarenc <pierre.crc_AT_gmailDOTcom>,
-# Samuel Renard <renard.samuel_AT_gmailDOTcom>,
-# Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Samuel Renard <renard.samuel_AT_gmailDOTcom>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
diff --git a/chimere/models.py b/chimere/models.py
index 4f6d4e0..85d4055 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -20,7 +20,7 @@
"""
Models description
"""
-import os, datetime, re, string
+import os, datetime, pyexiv2, re, string
import simplejson as json
from lxml import etree
from PIL import Image
@@ -563,11 +563,44 @@ def scale_image(max_x, pair):
new_y = (float(max_x) / x) * y
return (int(max_x), int(new_y))
+
+IMAGE_EXIF_ORIENTATION_MAP = {
+ 1: 0,
+ 8: 2,
+ 3: 3,
+ 6: 4,
+}
+
+PYEXIV2_OLD_API = not hasattr(pyexiv2, 'ImageMetadata')
+
def picturefile_post_save(sender, **kwargs):
if not kwargs['instance']:
return
picturefile = kwargs['instance']
+ if kwargs['created']:
+ filename = picturefile.picture.path
+ metadata = None
+ if PYEXIV2_OLD_API:
+ metadata = pyexiv2.Image(filename)
+ metadata.readMetadata()
+ else:
+ metadata = pyexiv2.ImageMetadata(filename)
+ metadata.read()
+ orientation = metadata['Exif.Image.Orientation'].value \
+ if 'Exif.Image.Orientation' in metadata else None
+ print "orientation", orientation
+ if orientation and orientation in IMAGE_EXIF_ORIENTATION_MAP \
+ and orientation > 1:
+ metadata['Exif.Image.Orientation'] = 1
+ if PYEXIV2_OLD_API:
+ metadata.writeMetadata()
+ else:
+ metadata.write()
+ im = Image.open(filename)
+ im = im.transpose(IMAGE_EXIF_ORIENTATION_MAP[orientation])
+ im.save(filename)
+
if not picturefile.thumbnailfile:
file = picturefile.picture
# defining the filename and the thumbnail filename
@@ -604,7 +637,7 @@ def picturefile_post_save(sender, **kwargs):
picturefile.thumbnailfile = short_name
picturefile.save()
- if not kwargs['instance'] or not kwargs['created']:
+ if not kwargs['created']:
return
pfs = PictureFile.objects.filter(marker=picturefile.marker).exclude(
pk=picturefile.pk).order_by('order')
diff --git a/debian/control b/debian/control
index 7317430..1c93646 100644
--- a/debian/control
+++ b/debian/control
@@ -1,9 +1,10 @@
Package: python-django-chimere
Version: 2.0
-Depends: python-django (>=1.3), python-gdal, python-psycopg2,
+Depends: python-django (>=1.4), python-gdal, python-psycopg2,
python-beautifulsoup, python-imaging, libjs-jquery,
libjs-jquery-ui, libjs-jquery-ui-theme-base,
postgresql-9.1, postgresql-9.1-postgis, gettext,
- python-simplejson, gpsbabel, python-django-south
+ python-simplejson, gpsbabel, python-django-south,
+ python-pyexiv2
Recommends: tinymce, python-django-celery, python-kombu
Suggests: libjs-jquery-ui-theme-south-street
diff --git a/docs/install.rst b/docs/install.rst
index 163c980..e1cb458 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -29,6 +29,7 @@ Prerequisites
- `gettext <http://www.gnu.org/software/gettext/>`_
- `psycopg2 <http://freshmeat.net/projects/psycopg/>`_
- `Python Imaging Library <http://www.pythonware.com/products/pil/>`_
+ - `pyexiv2 <http://tilloy.net/dev/pyexiv2/>`_
- `Beautiful Soup <http://www.crummy.com/software/BeautifulSoup/>`_
- python-simplejson
- python-gdal
@@ -60,7 +61,8 @@ Linux distribution repositories. For instance on Debian Wheezy::
python-beautifulsoup tinymce apache2 libgeos-3.3.3 proj-bin gdal-bin \
python-gdal python-lxml python-psycopg2 python-imaging gettext \
postgresql-9.1 postgresql-9.1-postgis libjs-jquery libjs-jquery-ui \
- python-django-celery python-simplejson python-gdal gpsbabel
+ python-django-celery python-simplejson python-gdal gpsbabel \
+ python-pyexiv2
On Debian Squeeze (you need to activate backports)::
@@ -70,7 +72,7 @@ On Debian Squeeze (you need to activate backports)::
apache2 libgeos-3.2.0 proj-bin gdal-bin python-gdal python-lxml \
python-psycopg2 python-imaging gettext postgresql-8.4 \
postgresql-8.4-postgis libjs-jquery libjs-jquery-ui python-simplejson \
- python-gdal gpsbabel
+ python-gdal gpsbabel python-pyexiv2
If these packages do not exist in your distribution's repository, please refer
diff --git a/docs/upgrade.rst b/docs/upgrade.rst
index aca3985..65e3734 100644
--- a/docs/upgrade.rst
+++ b/docs/upgrade.rst
@@ -44,7 +44,7 @@ Activate the backports: http://backports-master.debian.org/Instructions/
Then install the new dependencies::
apt-get install -t squeeze-backports python-django python-django-south \
- python-simplejson libjs-jquery-ui python-unidecode
+ python-simplejson libjs-jquery-ui python-pyexiv2
Debian Wheezy
+++++++++++++
@@ -52,7 +52,7 @@ Debian Wheezy
.. code-block:: bash
apt-get install python-django-south python-simplejson libjs-jquery-ui \
- python-unidecode
+ python-pyexiv2
If you are planing to do major import consider the install of `Celery
<http://celeryproject.org/>`_.