Guest User

Untitled

a guest
Mar 26th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. from PIL import Image
  2. from PIL import ImageFont
  3. from PIL import ImageDraw
  4.  
  5. colors_list = []
  6.  
  7. def color_appender(name, hexcode, rgb):
  8.     global colors_list
  9.     colors_list.append({
  10.             'name': name,
  11.             'hexcode': hexcode,
  12.             'rgb': rgb
  13.             })
  14.  
  15. def color_importer():
  16.     with open('colors.txt', 'r') as color_file:
  17.         colors_import = color_file.readlines()
  18.     for line in colors_import:
  19.         line    = line.strip()
  20.         line    = line.split(',')
  21.         name    = line[0].split('/')[0]
  22.         hexcode = line[1].lower()
  23.         rgb     = (int(line[-3]), int(line[-2]), int(line[-1]))
  24.         color_appender(name, hexcode, rgb)
  25.  
  26. fontx = 'fonts/MinecraftRegular-Bmg3.otf'
  27.  
  28. def make_pape(color):
  29.     luminance = ( (0.299 * color['rgb'][0]) + (0.587 * color['rgb'][1]) + (0.114 * color['rgb'][2]) ) / 255
  30.     print(color['name'], luminance)
  31.     if luminance > 0.8:
  32.         text_color = 'black'
  33.     else:
  34.         text_color = 'white'
  35.     img = Image.new(mode='RGB', size=(3*1920, 3*1080), color=color['rgb'])
  36.     draw = ImageDraw.Draw(img)
  37.     font = ImageFont.truetype(font=fontx, size=3*20)
  38.     draw.rectangle(((3*832, 3*412),(3*1090,3*670)), fill=None, outline=text_color, width=3*5)
  39.     draw.text((3*847, 3*427), text=color['name'], font=font, fill=text_color)
  40.     draw.text((3*847, 3*451), text='HEX ' + color['hexcode'], font=font, fill=text_color)
  41.     draw.text((3*847, 3*475), text='RGB ' + ' '.join(map(str,color['rgb'])), font=font, fill=text_color)
  42.     img.resize((1920, 1080))
  43.     img.save(color['name'] + '.png')
  44.  
  45. color_importer()
  46.  
  47. how_much = 5
  48. for color in colors_list[:how_much]:
  49.     make_pape(color)
Advertisement
Add Comment
Please, Sign In to add comment