PythonのモジュールであるPython Image Library (PIL)で画像にテキストを出力する方法. PILはnumpyのarrayから画像を生成してくれるので重宝していたのだが, 欲を出してテキストを付加することにした. これも非常に簡単にできる. 以下に文字を画像のちょうど中心にくるように出力するプログラムをメモしておく. import numpy import PIL.Image import PIL.ImageDraw import PIL.ImageFont def draw_text_at_center(img, text): draw = PIL.ImageDraw.Draw(img) draw.font = PIL.ImageFont.truetype( "/usr/share/fonts/truetype/freefont/FreeMono.ttf", 20