Merge pull request #9 from yuce/master

This commit is contained in:
Simon
2013-01-13 00:05:34 +01:00

View File

@@ -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)