0
0

More than 3 years have passed since last update.

文字が入った画像をpythonで作る(日本語)

Posted at

背景

そんなにない

作業

  • fontファイルの場所を調べる
$ fc-match -f "%{file}\n" FreeMono 
/System/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc
  • 画像作る
from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("/System/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc", size=60)

def make_image(n):
    im = Image.new("RGB",(300,100),"blue")
    draw = ImageDraw.Draw(im)# im上のImageDrawインスタンスを作る
    draw.text((10,20), f"自由記述欄{n}", font=font)
    im.save(f"./freetext{n}.jpg")

for i in range(0,50):
    make_image(i)
  • jupyter notebookで表示したかったら
from IPython.display import Image, display_png
display_png(Image('./name1.jpg'))

成果物

name46.jpg

freetext1.jpg

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0