Advertisement
Peaser

hash to colorsheet

Aug 3rd, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. import hashlib
  2. from PIL import Image
  3. from PIL import ImageFont
  4. from PIL import ImageDraw
  5.  
  6. width, height = (1000, 500) #<--- Image dimensions, CUSTOMIZE THIS!
  7.  
  8. def chop(object,length):
  9.     return [object[i:i+length] for i in range(0, len(object), length)]
  10.  
  11. def recur2(object, amt):
  12.     p1 = []
  13.     p2 = []
  14.     p3 = []
  15.     p4 = []
  16.     p5 = []
  17.     for i in range(amt):
  18.         p1.append(object[0])
  19.         p2.append(object[1])
  20.         p3.append(object[2])
  21.         p4.append(object[3])
  22.         p5.append(object[4])
  23.     result = []
  24.     for i in p1:
  25.         result.append(i)
  26.     for i in p2:
  27.         result.append(i)
  28.     for i in p3:
  29.         result.append(i)
  30.     for i in p4:
  31.         result.append(i)
  32.     for i in p5:
  33.         result.append(i)
  34.     return result
  35.  
  36. def comma(x):
  37.     if type(x) not in [int, long]:
  38.         raise TypeError("x must be a valid integer")
  39.     if x < 0:
  40.         return '-' + comma(-x)
  41.     f = ''
  42.     while x >= 1000:
  43.         x, r = divmod(x, 1000)
  44.         f = ",%03d%s" % (r, f)
  45.     return "%d%s" % (x, f)
  46.  
  47. def colfhex(value):
  48.     lv = len(value)
  49.     return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))
  50. try:
  51.     b = hashlib.md5(raw_input(">>>")).hexdigest()
  52.  
  53.     hexy_bits = chop(b, 6)[:-1]
  54.     remainder = chop(b, 6)[-1:]
  55.     color_pallet = [colfhex(i) for i in hexy_bits]
  56.     colordata = recur2(color_pallet, width/5)
  57.     img = Image.new('RGB', (width,height), "white")
  58.     img.putdata(colordata*height)
  59.     draw = ImageDraw.Draw(img)
  60.     font = ImageFont.truetype("arial.ttf", 50)
  61.     draw.text((0, 0),"+"+remainder[0],(255,255,255),font=font)
  62.     img.show()
  63.  
  64. except IndexError: print "Input too short! Must be greater than 6 characters."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement