diff --git a/sigal/image.py b/sigal/image.py index bc6fdc5..2cb722e 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -34,6 +34,10 @@ from PIL import Image as PILImage from PIL import ImageDraw, ImageOps +# EXIF specs Orientation constant +EXIF_ORIENTATION_TAG = 274 + + class Image: """ Image container @@ -48,6 +52,15 @@ class Image: self.imgname = os.path.split(filename)[1] self.img = PILImage.open(filename) + exif = self.img._getexif() + orientation = exif.get(EXIF_ORIENTATION_TAG) + + # see: http://www.impulseadventure.com/photo/exif-orientation.html + rotate_map = {3: 180, 6: -90, 8: 90} + rotation = rotate_map.get(orientation) + if rotation: + self.img = self.img.rotate(rotation) + def save(self, filename, quality=90): self.img.save(filename, quality=quality)