changeset 208:71fba6d8d138

implement exif-tag based web/thumbnail rotation
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 04 Aug 2008 12:58:49 +0200
parents 08965faaa4ff
children 475844e1d7a3
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Mon Jul 21 20:40:44 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Mon Aug 04 12:58:49 2008 +0200
@@ -555,7 +555,23 @@
            # XXX later, a unit conversion method for using other units than 'px' is needed
             if not cache.exists(self.request, webnail):
                 if not self.image_for_webnail:
+                    exif = im_obj._getexif()
                     im_obj.thumbnail((int(self.webnail_width.strip('px')), int(self.webnail_width.strip('px'))), Image.ANTIALIAS)
+                    if exif:
+                        try:
+                            process = {
+                                1: lambda x: x,
+                                2: lambda x: x.transpose(Image.FLIP_LEFT_RIGHT),
+                                3: lambda x: x.transpose(Image.ROTATE_180),
+                                4: lambda x: x.transpose(Image.FLIP_TOP_BOTTOM),
+                                5: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM),
+                                6: lambda x: x.transpose(Image.ROTATE_270),
+                                7: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_LEFT_RIGHT),
+                                8: lambda x: x.transpose(Image.ROTATE_90),
+                            }
+                            im_obj = process[exif[274]](im_obj)
+                        except KeyError:
+                            pass
                     buf = StringIO.StringIO()
                     im_obj.save(buf, image_type)
                     buf.flush()