import sys
from PIL import Image
im = Image.open(sys.argv[1])
print("File: {}".format(sys.argv[1]))
print("Size: {} x {}".format(im.size[0], im.size[1]))
print("Mode: {}".format(im.mode))
if im.mode == 'P':
print()
print("Palette:")
lut = im.resize((256, 1))
lut.putdata(range(256))
lut = lut.convert("RGB").getdata()
for i, entry in enumerate(lut):
print(" {:3d}: {:3d} {:3d} {:3d}".format(i, entry[0], entry[1], entry[2]))
print()
separator = " " + "== == == ==.== == == ==:== == == ==.== == == ==|== == == ==.== == == ==:== == == ==.== == == =="
for y in range(im.size[1]):
print(separator)
prefix = "y = {:3d}: ".format(y)
line = []
for x in range(im.size[0]):
c = im.getpixel((x, y))
ct = "{:02x}".format(c)
if len(line) == 32:
print("{}{}".format(prefix, " ".join(line)))
prefix = " "
line = []
line.append(ct)
if line:
print("{}{}".format(prefix, " ".join(line)))
print(separator)