Commit c90b3306 authored by Malte Schmitz's avatar Malte Schmitz

Add ANSI color printing

parent 19332acf
...@@ -13,6 +13,10 @@ def encode(a): ...@@ -13,6 +13,10 @@ def encode(a):
result |= b << i * 3 + 2 result |= b << i * 3 + 2
return hex(result) return hex(result)
def ansiColor(rgb):
r,g,b = [v * 255 for v in rgb]
return "\033[48;2;{r};{g};{b}m \033[0m".format(r = r, g = g, b = b)
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("Missing file name argument", file=sys.stderr) print("Missing file name argument", file=sys.stderr)
sys.exit(1) sys.exit(1)
...@@ -22,6 +26,8 @@ img = Image.open(filename).convert('RGB') ...@@ -22,6 +26,8 @@ img = Image.open(filename).convert('RGB')
width, height = img.size width, height = img.size
pixels = [[mapColors(img.getpixel((x,y))) for y in range(height)] for x in range(width)] pixels = [[mapColors(img.getpixel((x,y))) for y in range(height)] for x in range(width)]
print("\n".join(["".join([ansiColor(v) for v in ps]) for ps in pixels]))
print()
array = "{" + ",".join([encode(p) for p in pixels]) + "}" array = "{" + ",".join([encode(p) for p in pixels]) + "}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment