PaletteOptimiser

Changeset

19:783e5bbb92a5
2015-09-18 Paul Boddie raw files shortlog changelog graph 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.
optimiser.py (file)
     1.1 --- a/optimiser.py	Thu Sep 10 16:19:23 2015 +0200
     1.2 +++ b/optimiser.py	Fri Sep 18 13:55:41 2015 +0200
     1.3 @@ -38,18 +38,18 @@
     1.4  tones = [
     1.5      "___", "_BB", "_BB", "BBB", # 00x
     1.6      "_GG", "__C", "_BC", "BCC", # 01x
     1.7 -    "_GG", "GGC", "BCC", "CCC", # 02x
     1.8 -    "GGG", "GCC", "CCC", "CCC", # 03x
     1.9 +    "_GG", "GGC", "BCW", "CCC", # 02x
    1.10 +    "GGG", "GGC", "GCW", "CCW", # 03x
    1.11      "_RR", "_MM", "BMM", "MBB", # 10x
    1.12 -    "_YY", "_**", "**B", "BBW", # 11x
    1.13 +    "_YY", "_**", "**B", "BBC", # 11x
    1.14      "_GY", "GGC", "*CC", "BCW", # 12x
    1.15 -    "GGY", "GGG", "GCC", "CCW", # 13x
    1.16 -    "_RR", "_RM", "*MM", "MMM", # 20x
    1.17 -    "RYY", "*RY", "M*W", "MMW", # 21x
    1.18 +    "BGY", "GGC", "CCW", "CCW", # 13x
    1.19 +    "_RR", "_RM", "*MM", "RMM", # 20x
    1.20 +    "RYY", "*RY", "RMM", "MMM", # 21x
    1.21      "YYY", "YYW", "*WW", "*WW", # 22x
    1.22 -    "YYY", "YYW", "GWW", "CWW", # 23x
    1.23 -    "RRR", "RRM", "RMM", "MMM", # 30x
    1.24 -    "RRY", "RRY", "RMW", "MMW", # 31x
    1.25 +    "YYY", "GYY", "GWW", "CWW", # 23x
    1.26 +    "RRR", "RRM", "BMR", "BMR", # 30x
    1.27 +    "RRY", "RRY", "RMW", "RMW", # 31x
    1.28      "YYY", "YYW", "YYW", "WWW", # 32x
    1.29      "YYY", "YYW", "YYW", "WWW", # 33x
    1.30      ]
    1.31 @@ -58,15 +58,23 @@
    1.32  
    1.33  if __name__ == "__main__":
    1.34      width = 320
    1.35 +    height = 256
    1.36 +
    1.37      input_filename, output_filename = sys.argv[1:3]
    1.38      rotate = "-r" in sys.argv[3:]
    1.39  
    1.40      x = EXIF.process_file(open(input_filename))
    1.41      im = PIL.Image.open(input_filename)
    1.42 -    if rotate or x["Image Orientation"].values == [6L]:
    1.43 +
    1.44 +    if rotate or x and x["Image Orientation"].values == [6L]:
    1.45          im = im.rotate(270)
    1.46 +
    1.47      w, h = im.size
    1.48 -    height = (width * h) / w
    1.49 +    if w > h:
    1.50 +        height = (width * h) / w
    1.51 +    else:
    1.52 +        width = (height * w) / h
    1.53 +
    1.54      im = im.resize((width, height))
    1.55  
    1.56      usage = []