From 703f54a037eebfb4523f3d6ca406e80de23d5f36 Mon Sep 17 00:00:00 2001 From: Spengreb Date: Thu, 14 Jan 2021 23:02:14 +0100 Subject: [PATCH] Add rounded edges to cards --- main.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 247f6dd..a0f8cdf 100755 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ def main(): special_cards = ['W', 'N'] for color in colors: - for i in range(1, 4): + for i in range(1, 3): draw_card_face(color, i) for sign in special_cards: @@ -25,6 +25,8 @@ def draw_card_face(color, symbol): img = draw_symbol(img, symbol, color, 90, 130) img = draw_symbol(img, symbol, color, int(img.width - 100), 130) img = draw_rune(img, color) + + draw_mask(img, color) save_img(img, color, symbol) def draw_symbol(img, symbol, color, x, y): @@ -46,6 +48,23 @@ def draw_rune(img, color): top=int((img.height - rune.height) / 2)) return img +def draw_mask(img, color): + # Mask with a pink outline. This pink outline is this replaced + # with a transparency layer before being returned + with Image(width=img.width, height=img.height, background=Color("#c300ff")) as mask: + with Drawing() as ctx: + ctx.fill_color = Color("black") + ctx.rectangle(left=0, + top=0, + width=mask.width, + height=mask.height, + radius=mask.width * 0.075) + ctx(mask) + + img.composite_channel('all_channels', mask, 'screen') + img.opaque_paint(target=Color("#c300ff"), fill=Color("transparent"), fuzz=0.30*img.quantum_range) + return img + def save_img(img, color, symbol): img.save(filename='output/card-{}-{}.png'.format(color, symbol))