# HG changeset patch # User Paul Boddie # Date 1441802320 -7200 # Node ID e9fa3d280806f2dd071c60243fd1a5a452d8c412 # Parent 9369980667e7fed0fe93f0373062cf53e0893599 Added automatic rotation detection. diff -r 9369980667e7 -r e9fa3d280806 optimiser.py --- a/optimiser.py Wed Sep 09 01:05:04 2015 +0200 +++ b/optimiser.py Wed Sep 09 14:38:40 2015 +0200 @@ -1,6 +1,7 @@ #!/usr/bin/env python from array import array +import EXIF import PIL.Image import sys @@ -43,8 +44,9 @@ scaled_filename = (sys.argv[3:] + [None])[0] rotate = "-r" in sys.argv[3:] + x = EXIF.process_file(open(input_filename)) im = PIL.Image.open(input_filename) - if rotate: + if rotate or x["Image Orientation"].values == [6L]: im = im.rotate(270) w, h = im.size height = (width * h) / w