Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from PIL import ImageFont
- from PIL import ImageDraw
- colors_list = []
- def color_appender(name, hexcode, rgb):
- global colors_list
- colors_list.append({
- 'name': name,
- 'hexcode': hexcode,
- 'rgb': rgb
- })
- def color_importer():
- with open('colors.txt', 'r') as color_file:
- colors_import = color_file.readlines()
- for line in colors_import:
- line = line.strip()
- line = line.split(',')
- name = line[0].split('/')[0]
- hexcode = line[1].lower()
- rgb = (int(line[-3]), int(line[-2]), int(line[-1]))
- color_appender(name, hexcode, rgb)
- fontx = 'fonts/MinecraftRegular-Bmg3.otf'
- def make_pape(color):
- luminance = ( (0.299 * color['rgb'][0]) + (0.587 * color['rgb'][1]) + (0.114 * color['rgb'][2]) ) / 255
- print(color['name'], luminance)
- if luminance > 0.8:
- text_color = 'black'
- else:
- text_color = 'white'
- img = Image.new(mode='RGB', size=(3*1920, 3*1080), color=color['rgb'])
- draw = ImageDraw.Draw(img)
- font = ImageFont.truetype(font=fontx, size=3*20)
- draw.rectangle(((3*832, 3*412),(3*1090,3*670)), fill=None, outline=text_color, width=3*5)
- draw.text((3*847, 3*427), text=color['name'], font=font, fill=text_color)
- draw.text((3*847, 3*451), text='HEX ' + color['hexcode'], font=font, fill=text_color)
- draw.text((3*847, 3*475), text='RGB ' + ' '.join(map(str,color['rgb'])), font=font, fill=text_color)
- img.resize((1920, 1080))
- img.save(color['name'] + '.png')
- color_importer()
- how_much = 5
- for color in colors_list[:how_much]:
- make_pape(color)
Advertisement
Add Comment
Please, Sign In to add comment