45 lines
1.4 KiB
Python
Executable file
45 lines
1.4 KiB
Python
Executable file
#!/usr/bin/python3
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
import json
|
|
|
|
H = 800
|
|
W = 300
|
|
M = 30
|
|
R = 60
|
|
|
|
font_path = "" # TODO gwent font
|
|
small_size = 10
|
|
big_size = 100
|
|
small_font = ImageFont.truetype(font_path, small_size)
|
|
big_font = ImageFont.truetype(font_path, big_size)
|
|
|
|
with open("cards/config.json") as f:
|
|
j = json.loads(f.read())
|
|
traits = { trait: Image.open("cards/images/traits/"+trait+".png") for trait in j["traits"] }
|
|
lines = { line: Image.open("cards/images/lines/"+line+".png") for line in j["lines"] }
|
|
factions = { faction: Image.open("cards/images/factions/"+faction+".png") for faction in j["factions"] }
|
|
|
|
def make_image(data):
|
|
image = Image.new("RGB", (W, H), (255, 255, 255))
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
draw.text((M, M), str(data["power"]), font=big_font)
|
|
|
|
image.paste(factions[data["faction"]], ((W-R)//2, M), mask=factions[data["faction"]])
|
|
|
|
image.paste(lines[data["line"]], (W-M-R, M), mask=lines[data["line"]])
|
|
|
|
draw.text(((W-len(data["name"]*small_size))/2, (H-small_size)/2), str(data["name"]), font=small_font)
|
|
|
|
for i in range(len(data["traits"])):
|
|
trait = data["traits"][i]
|
|
image.paste(traits[trait], (H-M-R,W-M-R*(i+1)), mask=lines[trait])
|
|
|
|
image.save(data["name"]+".png", "PNG")
|
|
|
|
with open("cards/cards.json") as f:
|
|
cards = json.loads(f.read())
|
|
print(cards)
|
|
|
|
for card in cards:
|
|
make_image(card)
|