#!/usr/bin/env python3 """Regenerates the three Wizard's Data images that had text typeset in the CC BY-ND font "Celtic Bit", with OFL fonts (Jacquard 24 for the title, Silkscreen for the pause and help labels). python3 wd_art.py """ import sys from PIL import Image, ImageDraw, ImageFont src, fonts, out = sys.argv[1:4] WHITE, DARK = (255, 255, 255, 255), (64, 64, 64, 255) def inpaint(im, box, is_text): px = im.load(); x0, y0, x1, y1 = box for y in range(y0, y1): for x in range(x0, x1): if is_text(px[x, y], x, y): xl = x while xl > x0 and is_text(px[xl, y], xl, y): xl -= 1 xr = x while xr < x1 - 1 and is_text(px[xr, y], xr, y): xr += 1 px[x, y] = px[xl, y] if not is_text(px[xl, y], xl, y) else px[xr, y] def outlined(draw_im, pos, text, font, fill, outline): d = ImageDraw.Draw(draw_im); d.fontmode = '1' x, y = pos for dx, dy in ((1, 0), (0, 1), (1, 1)): d.text((x + dx, y + dy), text, font=font, fill=outline) d.text((x, y), text, font=font, fill=fill) def title(font_file, size, lines, ys): im = Image.open(f'{src}/title_bg_2x.png').convert('RGBA') def is_text(c, x, y): return c in (WHITE, DARK) and not (x >= 232 and y >= 50) inpaint(im, (50, 26, 275, 80), is_text) f = ImageFont.truetype(f'{fonts}/{font_file}', size) for text, y in zip(lines, ys): w = f.getbbox(text)[2] outlined(im, ((320 - w) // 2 - 8, y), text, f, WHITE, DARK) return im def paused(): im = Image.open(f'{src}/paused_2x.png').convert('RGBA'); px = im.load() # the lettering and its underline are the black pixels inside the top of the scroll; rows 4-7 are the lighter # band, rows 8 and below the darker paper for y in range(4, 22): for x in range(21, 82): if px[x, y] == (0, 0, 0, 255): px[x, y] = px[20, y] f = ImageFont.truetype(f'{fonts}/Jacquard12-Regular.ttf', 20) d = ImageDraw.Draw(im); d.fontmode = '1' bb = f.getbbox('Paused'); w = bb[2] - bb[0] x = 46 - w // 2 - bb[0] d.text((x, 4 - bb[1] + 1), 'Paused', font=f, fill=(0, 0, 0, 255)) d.rectangle((46 - w // 2, 19, 46 - w // 2 + w - 1, 20), fill=(0, 0, 0, 255)) return im def help_(): im = Image.open(f'{src}/help_2x.png').convert('RGBA'); px = im.load() for y in range(im.height): for x in range(52, im.width): px[x, y] = (255, 0, 255, 255) f = ImageFont.truetype(f'{fonts}/Jersey10-Regular.ttf', 20) d = ImageDraw.Draw(im); d.fontmode = '1' for text, (g0, g1) in zip(('Run', 'Jump', 'Enter Door', 'Grab Scroll'), ((2, 13), (24, 35), (48, 59), (68, 79))): bb = f.getbbox(text) d.text((54, (g0 + g1) // 2 - (bb[1] + bb[3]) // 2), text, font=f, fill=(166, 132, 115, 255)) return im if __name__ == '__main__': title('Jacquard24-Regular.ttf', 32, ["The Wizard's", "Data"], [24, 50]).save(f'{out}/title_bg_2x.png') paused().save(f'{out}/paused_2x.png') help_().save(f'{out}/help_2x.png')