Alyssa

Pallete Convert

Jun 29th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from PIL import Image
  2. import sys
  3. import math
  4.  
  5. rgb_code_dictionary = {
  6.     (159, 213, 182): "592168591504179220",
  7.     (64, 224, 208): "549387534845607966",
  8.     (0, 255, 127): "594640072536621056",
  9.     (28, 30, 38): "592168591428681748",
  10.     (219, 4, 4): "543637320272707605",
  11.     (205, 2, 255): "549387535017836594",
  12.     (247, 168, 184): "543637320159723521",
  13.     (255, 140, 0): "592168591843917835",
  14.     (232, 232, 232): "592168410557972504",
  15.     (200, 6, 109): "592168240227024916",
  16.     (255, 29, 206): "534853890848456714",
  17.     (0, 129, 31): "592168591395127316",
  18.     (163, 163, 163): "592168410411171852",
  19.     (241, 196, 15): "534853738679238668",
  20.     (255, 77, 15): "592168239891742730",
  21.     (255, 248, 175): "592168238943830026",
  22.     (53, 60, 244): "534854148697489428"
  23. }
  24.  
  25. def distance(c1, c2):
  26.     (r1,g1,b1) = c1
  27.     (r2,g2,b2) = c2
  28.     return math.sqrt((r1 - r2)**2 + (g1 - g2) ** 2 + (b1 - b2) **2)
  29.  
  30. colors = list(rgb_code_dictionary.keys())
  31.  
  32. im = Image.open(sys.argv[1])
  33. d = im.size
  34.  
  35. world = []
  36.  
  37. print("Loading " + sys.argv[1] + " " + str(d[0]) + " x " + str(d[1]) + "\n")
  38.  
  39. for y in range(d[1]):
  40.     line = ""
  41.     for x in range(d[0]):
  42.         col = im.getpixel((x,y))
  43.         col = col[0:3]
  44.         closest = sorted(colors, key=lambda color: distance(color, col))[0]
  45.         line += "<:_:" + rgb_code_dictionary[closest] + ">"
  46.     print(line)
Advertisement
Add Comment
Please, Sign In to add comment