Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import sys
- import math
- rgb_code_dictionary = {
- (159, 213, 182): "592168591504179220",
- (64, 224, 208): "549387534845607966",
- (0, 255, 127): "594640072536621056",
- (28, 30, 38): "592168591428681748",
- (219, 4, 4): "543637320272707605",
- (205, 2, 255): "549387535017836594",
- (247, 168, 184): "543637320159723521",
- (255, 140, 0): "592168591843917835",
- (232, 232, 232): "592168410557972504",
- (200, 6, 109): "592168240227024916",
- (255, 29, 206): "534853890848456714",
- (0, 129, 31): "592168591395127316",
- (163, 163, 163): "592168410411171852",
- (241, 196, 15): "534853738679238668",
- (255, 77, 15): "592168239891742730",
- (255, 248, 175): "592168238943830026",
- (53, 60, 244): "534854148697489428"
- }
- def distance(c1, c2):
- (r1,g1,b1) = c1
- (r2,g2,b2) = c2
- return math.sqrt((r1 - r2)**2 + (g1 - g2) ** 2 + (b1 - b2) **2)
- colors = list(rgb_code_dictionary.keys())
- im = Image.open(sys.argv[1])
- d = im.size
- world = []
- print("Loading " + sys.argv[1] + " " + str(d[0]) + " x " + str(d[1]) + "\n")
- for y in range(d[1]):
- line = ""
- for x in range(d[0]):
- col = im.getpixel((x,y))
- col = col[0:3]
- closest = sorted(colors, key=lambda color: distance(color, col))[0]
- line += "<:_:" + rgb_code_dictionary[closest] + ">"
- print(line)
Advertisement
Add Comment
Please, Sign In to add comment