Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from PIL import ImageDraw
- from PIL import ImageFont
- import csv
- from tqdm import tqdm
- def generate_card(mg_name, mg_family, mg_type, mg_nature,
- portrait_filename, portrait_x_offset, portrait_y_offset,
- nature_x_offset, nature_y_offset):
- family_font = ImageFont.truetype('StrongGirls DEMO.otf', 90)
- nature_font = ImageFont.truetype('StrongGirls DEMO.otf', 60)
- dot_font = ImageFont.truetype('dejavu-sans.book.ttf', 90)
- name_font = ImageFont.truetype('StrongGirls DEMO.otf', 200)
- card = Image.open(r"base.png")
- underline = Image.open(r"brown_underline.png")
- portrait = Image.open(portrait_filename)
- card_width = card.size[0]
- portrait_width = portrait.size[0]
- x_offset = int((0.5)*(card_width - portrait_width)) + portrait_x_offset
- Image.Image.paste(card, portrait, (x_offset, 1100 + portrait_x_offset), portrait)
- draw = ImageDraw.Draw(card)
- name_anchor = (550, 200)
- draw.text(name_anchor, mg_name, font=name_font, fill=(0, 0, 0), stroke_width=0, stroke_fill="black")
- family_type_anchor = (450,550)
- draw.text(family_type_anchor, "Family: " + mg_family + " ", font=family_font, fill=(0, 0, 0), stroke_width=0, stroke_fill="black")
- end = draw.textbbox(text="Family: " + mg_family + " ", font=family_font, xy=family_type_anchor)[2]
- draw.text((end,family_type_anchor[1]-10), u"\u2022", font=dot_font, fill=(0, 0, 0))
- end = draw.textbbox(text=u"\u2022", font=dot_font, xy=(end,family_type_anchor[1]-10))[2]
- draw.text((end,family_type_anchor[1]), " Type: " + mg_type, font=family_font, fill=(0, 0, 0), stroke_width=0, stroke_fill="black")
- nature_anchor = (200,900)
- draw.text(nature_anchor, " Nature: " + mg_nature, font=nature_font, fill=(0, 0, 0), stroke_width=0, stroke_fill="black")
- Image.Image.paste(card, underline, (nature_anchor[0]+14,nature_anchor[1]+60))
- card.save(mg_name + ".png")
- with open('data_sheet.csv') as f:
- reader = csv.DictReader(f, delimiter=';')
- for row in tqdm(reader):
- mg_name = row['name']
- mg_family = row['family']
- mg_type = row['type']
- mg_nature = row['nature']
- portrait_filename = row['portrait_filename']
- portrait_x_offset = int(row['portrait_x_offset'])
- portrait_y_offset = int(row['portrait_y_offset'])
- nature_x_offset = int(row['nature_x_offset'])
- nature_y_offset = int(row['nature_y_offset'])
- generate_card(mg_name, mg_family, mg_type, mg_nature, portrait_filename,
- portrait_x_offset, portrait_y_offset, nature_x_offset, nature_y_offset)
Advertisement
Add Comment
Please, Sign In to add comment