challenge.py

1.1 kB · python · 42 lines

1import lib  # noqa: F40123from PIL import Image, ImageDraw, ImageFont45from lib.canvas import INK, PAPER, quantize6from lib.gif import write_gif7from lib.paths import FILES, GIFS, ensure, show89IMAGES = FILES / "old" / "images"10NUMBERS = [0, 3, 5, 7, 9]11SIZE = 81012STRIP = 11013GREYS = 161415# FRAME1617def label(canvas, name):18    try:19        font = ImageFont.load_default(48)20    except TypeError:21        font = ImageFont.load_default()22    ImageDraw.Draw(canvas).text((30, SIZE - 78), name, fill=INK.r, font=font)2324def frame(number):25    name = "MrlyGram-%d" % number26    image = Image.open(IMAGES / (name + ".png")).convert("L")27    image.thumbnail((SIZE, SIZE - STRIP), Image.LANCZOS)28    canvas = Image.new("L", (SIZE, SIZE), PAPER.r)29    canvas.paste(image, ((SIZE - image.width) // 2, (SIZE - STRIP - image.height) // 2))30    label(canvas, name)31    return quantize(canvas, GREYS)3233# RUN3435def main():36    ensure()37    path = GIFS / "challenge.gif"38    write_gif(path, [frame(number) for number in NUMBERS])39    print("%s (%s)" % (show(path), " ".join("MrlyGram-%d" % n for n in NUMBERS)))4041if __name__ == "__main__":42    main()