Loading

Paste #pej6sox8c

  1. import sys
  2. from PIL import Image
  3.  
  4. im = Image.open(sys.argv[1])
  5. print("File: {}".format(sys.argv[1]))
  6. print("Size: {} x {}".format(im.size[0], im.size[1]))
  7. print("Mode: {}".format(im.mode))
  8.  
  9. if im.mode == 'P':
  10.     print()
  11.     print("Palette:")
  12.     lut = im.resize((256, 1))
  13.     lut.putdata(range(256))
  14.     lut = lut.convert("RGB").getdata()
  15.     for i, entry in enumerate(lut):
  16.         print("    {:3d}: {:3d} {:3d} {:3d}".format(i, entry[0], entry[1], entry[2]))
  17.  
  18. print()
  19.  
  20. separator = "         " + "== == == ==.== == == ==:== == == ==.== == == ==|== == == ==.== == == ==:== == == ==.== == == =="
  21. for y in range(im.size[1]):
  22.     print(separator)
  23.     prefix = "y = {:3d}: ".format(y)
  24.     line = []
  25.     for x in range(im.size[0]):
  26.         c = im.getpixel((x, y))
  27.         ct = "{:02x}".format(c)
  28.  
  29.         if len(line) == 32:
  30.             print("{}{}".format(prefix, " ".join(line)))
  31.             prefix = "         "
  32.             line = []
  33.  
  34.         line.append(ct)
  35.  
  36.     if line:
  37.         print("{}{}".format(prefix, " ".join(line)))
  38. print(separator)

Comments