# HG changeset patch # User Paul Boddie # Date 1442577341 -7200 # Node ID 783e5bbb92a5c0a5b2467a1fc9c9b63bfb00ecbd # Parent 99ab2ac4125aff1473f4f97e933f7e3cf39b5362 Impose a maximum height on portrait images. Adjusted the colourmap to employ combinations of light/dark colours as approximations of the preferred colour in some cases. diff -r 99ab2ac4125a -r 783e5bbb92a5 optimiser.py --- a/optimiser.py Thu Sep 10 16:19:23 2015 +0200 +++ b/optimiser.py Fri Sep 18 13:55:41 2015 +0200 @@ -38,18 +38,18 @@ tones = [ "___", "_BB", "_BB", "BBB", # 00x "_GG", "__C", "_BC", "BCC", # 01x - "_GG", "GGC", "BCC", "CCC", # 02x - "GGG", "GCC", "CCC", "CCC", # 03x + "_GG", "GGC", "BCW", "CCC", # 02x + "GGG", "GGC", "GCW", "CCW", # 03x "_RR", "_MM", "BMM", "MBB", # 10x - "_YY", "_**", "**B", "BBW", # 11x + "_YY", "_**", "**B", "BBC", # 11x "_GY", "GGC", "*CC", "BCW", # 12x - "GGY", "GGG", "GCC", "CCW", # 13x - "_RR", "_RM", "*MM", "MMM", # 20x - "RYY", "*RY", "M*W", "MMW", # 21x + "BGY", "GGC", "CCW", "CCW", # 13x + "_RR", "_RM", "*MM", "RMM", # 20x + "RYY", "*RY", "RMM", "MMM", # 21x "YYY", "YYW", "*WW", "*WW", # 22x - "YYY", "YYW", "GWW", "CWW", # 23x - "RRR", "RRM", "RMM", "MMM", # 30x - "RRY", "RRY", "RMW", "MMW", # 31x + "YYY", "GYY", "GWW", "CWW", # 23x + "RRR", "RRM", "BMR", "BMR", # 30x + "RRY", "RRY", "RMW", "RMW", # 31x "YYY", "YYW", "YYW", "WWW", # 32x "YYY", "YYW", "YYW", "WWW", # 33x ] @@ -58,15 +58,23 @@ if __name__ == "__main__": width = 320 + height = 256 + input_filename, output_filename = sys.argv[1:3] rotate = "-r" in sys.argv[3:] x = EXIF.process_file(open(input_filename)) im = PIL.Image.open(input_filename) - if rotate or x["Image Orientation"].values == [6L]: + + if rotate or x and x["Image Orientation"].values == [6L]: im = im.rotate(270) + w, h = im.size - height = (width * h) / w + if w > h: + height = (width * h) / w + else: + width = (height * w) / h + im = im.resize((width, height)) usage = []