Pythonで経済を回す

もはや何番煎じかわからないやつ。

f:id:Inaab:20180205015250g:plain:w200

from PIL import Image, ImageDraw, ImageFont

OUTPUT_NAME = 'economy.gif'
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
WIDTH, HEIGHT = 500, 500
IMAGE_SIZE = (WIDTH, HEIGHT)
FONT_PATH = '/home/inab/.local/share/fonts/migu-1m/migu-1m-regular.ttf'
FONT_SIZE = 100
FONT = ImageFont.truetype(FONT_PATH, FONT_SIZE)
TEXT = '経済'

def get_position(p1, p2):
    return (p1[0] - p2[0]) / 2, (p1[1] - p2[1]) / 2

def main():
    images = []
    for i in range(0, 360, 12):
        image = Image.new('RGB', IMAGE_SIZE, WHITE)
        txt = Image.new('RGBA', IMAGE_SIZE, WHITE)
        draw = ImageDraw.Draw(txt)
        draw.font = FONT
        pos = get_position(IMAGE_SIZE, FONT.getsize(TEXT))
        draw.text(pos, TEXT, BLACK)
        txt = txt.rotate(i)
        image.paste(txt, txt.split()[3])
        images.append(image)

    im = images.pop(0)
    im.save(OUTPUT_NAME, save_all=True, append_images=images,
            optimize=False, duration=40, loop=0)

main()

参考

note.nkmk.me