def draw_card(img_path, height=420, width=420):
"""
Loads an image, rescales it and adds a border.
"""
= Image.open(img_path).convert("RGBA")
img1 = img1.resize((height, width))
img1 = Image.new("RGBA", (height, width))
img2 = ImageDraw.Draw(img1)
draw1 = ImageDraw.Draw(img2)
draw 0, 0) + img2.size, fill=128)
draw.line((0, img2.size[1], img2.size[0], 0), fill=128)
draw.line((= 10, 20
f_outer, f_inner 0, 0), (img2.size[0], img2.size[1])], fill = (140, 50, 100, 255))
draw.rectangle([(0]-f_outer, img2.size[1]-f_outer)], fill = (255, 255, 255, 255), radius=20)
draw.rounded_rectangle([(f_outer, f_outer), (img2.size[0]-f_inner, img2.size[1]-f_inner)], fill = (255, 255, 255, 0), outline=(255, 255, 255, 255), radius=20)
draw.rounded_rectangle([(f_inner, f_inner), (img2.size[return Image.alpha_composite(img1, img2,)
Drawer
draw_card
draw_card (img_path, height=420, width=420)
Loads an image, rescales it and adds a border.
def load_taboo_words(file_path):
with open(file_path, 'r') as f:
= json.load(f)
out return out
load_taboo_words
load_taboo_words (file_path)
def add_taboo_words(img, words):
"""
Adds the taboo words to an image to make it a Taboo card.
"""
= list(words.items())[0]
top_w, forb_ws = _capitalize_all(top_w)
top_w = [_capitalize_all(w) for w in forb_ws]
forb_ws = Image.new("RGBA", img.size)
new_im = ImageDraw.Draw(new_im)
draw 50, 50), (img.width-50, 100)], fill = (255, 255, 255, 50), radius=20)
draw.rounded_rectangle([(= 10
start_font_size = start_font_size
fontsize = _resize_font(top_w, img.width-100, 50)
font // 2, 75), top_w, fill=(0, 0, 0, 255), anchor="mm", font=font)
draw.text((img.width
for idx, forb_w in enumerate(forb_ws[:5]):
= (50 / 2.5) + (idx + 1) * (50)
down_shift 70, 50 + down_shift), (img.width-70, 90 + down_shift)], fill = (255, 255, 255, 50), radius=20)
draw.rounded_rectangle([(= _resize_font(forb_w, img.width-140, 40)
font // 2, 70 + down_shift), forb_w, fill=(0, 0, 0, 255), anchor="mm", font=font)
draw.text((img.width
return Image.alpha_composite(img, new_im,)
add_taboo_words
add_taboo_words (img, words)
Adds the taboo words to an image to make it a Taboo card.